﻿#include "dataanalysiswindow.h"
#include "ui_dataanalysiswindow.h"
#include "mainwindow.h"
#include "dataAnalysisThread.h"

extern QString filep;
extern QString isc;
class ReadOnlyDelegate: public QItemDelegate
{

public:
    ReadOnlyDelegate(QWidget *parent = NULL):QItemDelegate(parent)
    {}

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const override //final
    {
        Q_UNUSED(parent)
        Q_UNUSED(option)
        Q_UNUSED(index)
        return NULL;
    }
};

DataAnalysisWindow::DataAnalysisWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DataAnalysisWindow)
{
    setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    ui->setupUi(this);
    myChart = new QChart();
    fxpzui = new fxpz();

    bzROX = new QLineSeries();
    bzVIC = new QLineSeries();
    bzFAM = new QLineSeries();
    bzCY5 = new QLineSeries();
    bzsdROX = new QScatterSeries();
    bzsdVIC = new QScatterSeries();
    bzsdFAM = new QScatterSeries();
    bzsdCY5 = new QScatterSeries();
    fbzROX = new QScatterSeries();
    fbzVIC = new QScatterSeries();
    fbzFAM = new QScatterSeries();
    fbzCY5 = new QScatterSeries();
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
    refWindow=true;
}

DataAnalysisWindow::~DataAnalysisWindow()
{
    delete ui;
}

void DataAnalysisWindow::showEvent(QShowEvent *event)
{
    ui->widget_2->setVisible(true);
    ui->widget_3->setVisible(true);

    ui->pushButton->setVisible(true);
    ui->pushButton_6->setVisible(true);
    ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/left.png);");
    ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
    if(refWindow){
        anscrui=new anscr();

        anscrui->sampleName="全部";
        anscrui->posInfo="全部";
        anscrui->testType="全部";

        myChart = new QChart();
        ui->graphicsView->setChart(myChart);//将图表放到画布上

        fThresholdLine=new QLineSeries();
        rThresholdLine=new QLineSeries();
        vThresholdLine=new QLineSeries();
        cThresholdLine=new QLineSeries();

        ui->tableWidget->blockSignals(true);
        ui->tableWidget->clear();
        ui->tableWidget->setRowCount(0);
        ui->tableWidget->setColumnCount(0);
        ui->tableWidget->blockSignals(false);
        anscrui->refDataList=true;

        ui->comboBox->blockSignals(true);
        ui->comboBox->clear();
        ui->comboBox->addItem("原始曲线");
        ui->comboBox->addItem("扩增曲线");
        ui->comboBox->addItem("标准曲线");
        ui->comboBox->addItem("指导建议");
        ui->comboBox->blockSignals(false);

        ui->checkBox->setVisible(false);
        ui->checkBox_2->setVisible(false);
        ui->checkBox_3->setVisible(false);
        ui->checkBox_4->setVisible(false);

        ui->checkBox->setChecked(false);
        ui->checkBox_2->setChecked(false);
        ui->checkBox_3->setChecked(false);
        ui->checkBox_4->setChecked(false);

        ui->widget_2->setVisible(true);
        ui->pushButton_13->setVisible(false);
        ui->pushButton_12->setVisible(false);
        ui->pushButton_7->setVisible(false);
        ui->pushButton_8->setVisible(false);
        ui->pushButton_11->setVisible(false);
        ui->pushButton_14->setVisible(false);
        ui->pushButton_15->setVisible(true);

        ui->pushButton->setVisible(true);
        ui->pushButton_6->setVisible(true);
        ui->FAMCheckBox->setVisible(true);
        ui->VICCheckBox->setVisible(true);
        ui->ROXCheckBox->setVisible(true);
        ui->CY5CheckBox->setVisible(true);

        ui->pushButton_2->show();
        ui->label_2->setVisible(false);
        ui->label_3->setVisible(false);
        ui->label_4->setVisible(false);
        ui->label_5->setVisible(false);

        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);

        QString sql="Select Name From ItemCode where IsDefault=1 and DicCode=11";
        query.exec(sql);
        while (query.next()) {
            defaultAccess = query.value("Name").toString();
        }

        sql="Select Name from ItemCode Where DicCode='7' and IsDefault='1'";
        query.exec(sql);
        while (query.next()) {
            ui->FAMCheckBox->setText(query.value("Name").toString());
        }

        sql="Select Name from ItemCode Where DicCode='8' and IsDefault='1'";
        query.exec(sql);
        while (query.next()) {
            ui->VICCheckBox->setText(query.value("Name").toString());
        }

        sql="Select Name from ItemCode Where DicCode='9' and IsDefault='1'";
        query.exec(sql);
        while (query.next()) {
            ui->ROXCheckBox->setText(query.value("Name").toString());
        }

        sql="Select Name from ItemCode Where DicCode='10' and IsDefault='1'";
        query.exec(sql);
        while (query.next()) {
            ui->CY5CheckBox->setText(query.value("Name").toString());
        }

        analyseClient = new Analyse();
        ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);

        if(MainWindow::experimentStatus.get()==4){
            QList<QString> fileList= MainWindow::experimentSaveDataPath.split('/');
            QString fileName=fileList[fileList.length()-1];
            ui->label->setText(QString("当前打开文件名称:%1").arg(fileName));

            sql="Select CycleNum from AmplStepTemp where ProgramId=(Select AmplGuid from ExperimentInfo) and "
                "CASE WHEN "
                "(Select count(*) from AmplStepTemp where ProgramId=(Select AmplGuid from ExperimentInfo) and IsCollect='是')>0 "
                "then "
                "IsCollect='是' "
                "else "
                "StepNum=(Select max(StepNum) from AmplStepTemp where programId=(Select AmplGuid from ExperimentInfo)) "
                "end";
            query.exec(sql);
            while (query.next()) {
                analyseClient->leh=query.value("CycleNum").toInt();
            }

            sql="Select Count(*) as Num From AmplStepTemp Where ProgramId=(Select AmplGuid From ExperimentInfo) and   IsCollect='是'";
            query.exec(sql);
            while(query.next()){
                isYing=query.value("Num")>0;
            }
            if(isYing){
                if(MainWindow::reAnalyse){
                    QTimer::singleShot(500,[this](){
                        tcts *tctsWindow = new tcts();
                        tctsWindow->infochange("提示","treat","正在执行数据分析,请稍候",false,true);
                        tctsWindow->show();

                        QTimer::singleShot(3000,tctsWindow,&tcts::close);

                        QTimer::singleShot(1000,[this](){
                            DataAnalysisByJThread *dataAnalyJ=new DataAnalysisByJThread();
                            dataAnalyJ->run(false);

                            refOriginalCurveChart();
                            refOriginalCurveTable();
                            MainWindow::reAnalyse = false;
                        });
                    });
                }
            }
        }else{
            ui->label->setText("");
            sql="Select CycleNum from AmplStep where ProgramId=(Select AmplGuid from ExperimentInfo) and "
                "CASE WHEN "
                "(Select count(*) from AmplStep where ProgramId=(Select AmplGuid from ExperimentInfo) and IsCollect='是')>0 "
                "then "
                "IsCollect='是' "
                "else "
                "StepNum=(Select max(StepNum) from AmplStep where programId=(Select AmplGuid from ExperimentInfo)) "
                "end";
            query.exec(sql);
            while (query.next()) {
                analyseClient->leh=query.value("CycleNum").toInt();
            }

            sql="Select Count(*) as Num From AmplStep Where ProgramId=(Select AmplGuid From ExperimentInfo) and   IsCollect='是'";
            query.exec(sql);
            while(query.next()){
                isYing=query.value("Num")>0;
            }
        }

        ui->CY5CheckBox->setChecked(true);
        ui->ROXCheckBox->setChecked(true);
        ui->VICCheckBox->setChecked(true);
        ui->FAMCheckBox->setChecked(true);

        if(MainWindow::experimentStatus.get()==4){
            ui->pushButton_9->show();
            ui->pushButton_10->show();
        }else{
            ui->pushButton_9->hide();
            ui->pushButton_10->hide();
        }

        ui->lineEdit->hide();
        ui->lineEdit_2->hide();
        ui->lineEdit_3->hide();
        ui->lineEdit_4->hide();

        if(!MainWindow::reAnalyse){
            refOriginalCurveChart();
            refOriginalCurveTable();
        }
        event->accept();
    }
}

//下拉框选择变更事件
void DataAnalysisWindow::on_comboBox_currentTextChanged(const QString &arg1)
{
    if(arg1=="原始曲线"){
        ui->widget_2->setVisible(true);
        ui->widget_3->setVisible(true);
        ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/left.png);");
        ui->pushButton_6->setVisible(true);
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        ui->pushButton->setVisible(true);
        vsfl1=0;
        vsfl2=0;
        refOriginalCurveChart();
        refOriginalCurveTable();
        ui->checkBox->setVisible(false);
        ui->checkBox_2->setVisible(false);
        ui->checkBox_3->setVisible(false);
        ui->checkBox_4->setVisible(false);

        ui->checkBox->setChecked(false);
        ui->checkBox_2->setChecked(false);
        ui->checkBox_3->setChecked(false);
        ui->checkBox_4->setChecked(false);

        ui->widget_2->setVisible(true);
        ui->pushButton_13->setVisible(false);
        ui->pushButton_12->setVisible(false);
        ui->pushButton_7->setVisible(false);
        ui->pushButton_8->setVisible(false);
        ui->pushButton_11->setVisible(false);
        ui->pushButton_14->setVisible(false);
        ui->pushButton_15->setVisible(true);

        ui->pushButton->setVisible(true);
        ui->pushButton_6->setVisible(true);
        ui->FAMCheckBox->setVisible(true);
        ui->VICCheckBox->setVisible(true);
        ui->ROXCheckBox->setVisible(true);
        ui->CY5CheckBox->setVisible(true);

        ui->pushButton_2->show();
        ui->label_2->setVisible(false);
        ui->label_3->setVisible(false);
        ui->label_4->setVisible(false);
        ui->label_5->setVisible(false);

    }else if(arg1 =="扩增曲线"){
        ui->widget_2->setVisible(true);
        ui->widget_3->setVisible(true);
        ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/left.png);");
        ui->pushButton_6->setVisible(true);
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        ui->pushButton->setVisible(true);
        vsfl1=0;
        vsfl2=0;
        ui->widget_2->setVisible(true);
        ui->widget_3->setVisible(true);
        refAmplificationCurveChart();
        refAmplificationCurveTable();

        ui->checkBox->setVisible(true);
        ui->checkBox_2->setVisible(true);
        ui->checkBox_3->setVisible(true);
        ui->checkBox_4->setVisible(true);

        ui->widget_2->setVisible(true);
        ui->pushButton_13->setVisible(false);
        ui->pushButton_12->setVisible(false);
        ui->pushButton_7->setVisible(false);
        ui->pushButton_8->setVisible(false);
        ui->pushButton_11->setVisible(false);
        ui->pushButton_14->setVisible(false);
        ui->pushButton_15->setVisible(true);

        ui->pushButton->setVisible(true);
        ui->pushButton_6->setVisible(true);
        ui->FAMCheckBox->setVisible(true);
        ui->VICCheckBox->setVisible(true);
        ui->ROXCheckBox->setVisible(true);
        ui->CY5CheckBox->setVisible(true);

        ui->pushButton_2->show();
        ui->label_2->setVisible(false);
        ui->label_3->setVisible(false);
        ui->label_4->setVisible(false);
        ui->label_5->setVisible(false);

    }else if(arg1=="标准曲线"){
        ui->widget_2->setVisible(true);
        ui->widget_3->setVisible(true);
        ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/left.png);");
        ui->pushButton_6->setVisible(true);
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        ui->pushButton->setVisible(true);
        vsfl1=0;
        vsfl2=0;
        ui->widget_2->setVisible(true);
        ui->widget_3->setVisible(true);
        refOriginalCurveTable();
        refAmplificationCurveTable();
        standardCurveChart();
        ui->checkBox->setChecked(false);
        ui->checkBox_2->setChecked(false);
        ui->checkBox_3->setChecked(false);
        ui->checkBox_4->setChecked(false);

        ui->checkBox->setVisible(false);
        ui->checkBox_2->setVisible(false);
        ui->checkBox_3->setVisible(false);
        ui->checkBox_4->setVisible(false);

        ui->widget_2->setVisible(true);
        ui->pushButton_13->setVisible(false);
        ui->pushButton_12->setVisible(false);
        ui->pushButton_7->setVisible(false);
        ui->pushButton_8->setVisible(false);
        ui->pushButton_11->setVisible(false);
        ui->pushButton_14->setVisible(false);
        ui->pushButton_15->setVisible(false);
        ui->pushButton->setVisible(true);
        ui->pushButton_6->setVisible(true);
        ui->FAMCheckBox->setVisible(true);
        ui->VICCheckBox->setVisible(true);
        ui->ROXCheckBox->setVisible(true);
        ui->CY5CheckBox->setVisible(true);

        ui->pushButton_2->show();
        ui->label_2->setVisible(false);
        ui->label_3->setVisible(false);
        ui->label_4->setVisible(false);
        ui->label_5->setVisible(false);

    }else if(arg1=="指导建议"){
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        refOriginalCurveTable();
        refAmplificationCurveTable();
        ui->widget_2->setVisible(false);
        ui->checkBox->setChecked(false);
        ui->checkBox_2->setChecked(false);
        ui->checkBox_3->setChecked(false);
        ui->checkBox_4->setChecked(false);

        ui->checkBox->setVisible(false);
        ui->checkBox_2->setVisible(false);
        ui->checkBox_3->setVisible(false);
        ui->checkBox_4->setVisible(false);

        ui->pushButton_13->setVisible(true);
        ui->pushButton_12->setVisible(true);
        ui->pushButton_7->setVisible(true);
        ui->pushButton_8->setVisible(true);
        ui->pushButton_11->setVisible(true);
        ui->pushButton_14->setVisible(true);
        ui->pushButton_15->setVisible(false);

        ui->pushButton->setVisible(false);
        ui->pushButton_6->setVisible(false);
        ui->FAMCheckBox->setVisible(false);
        ui->VICCheckBox->setVisible(false);
        ui->ROXCheckBox->setVisible(false);
        ui->CY5CheckBox->setVisible(false);

        ui->pushButton_2->hide();
        standardCurveChart();
        guide();
        ui->label_2->setVisible(true);
        ui->label_3->setVisible(true);
        ui->label_4->setVisible(true);
        ui->label_5->setVisible(true);
        ui->widget_3->setVisible(true);
    }
}

//刷新原始曲线
void DataAnalysisWindow::refOriginalCurveChart(){
    myChart = new QChart();
    allOrigLines.clear();

    QValueAxis * axisY = new QValueAxis(myChart);//Y轴
    QValueAxis * axisX = new QValueAxis(myChart);//X轴为时间轴

    myChart->addAxis(axisY,Qt::AlignmentFlag::AlignLeft);//绑定Y轴到图表左侧
    myChart->addAxis(axisX,Qt::AlignmentFlag::AlignBottom);//绑定X轴到图表底部

    QString sql= GetChartQueryPosition();
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.exec(sql);
    QList<QVariantMap> positionList;
    int maxY=2000;

    while(query.next()){
        QVariantMap map;
        for (int i = 0; i < query.record().count(); ++i) {
            map[query.record().fieldName(i)] = query.value(i);
        }
        positionList.append(map);
    }
    QString islv;
    sql="Select * From DataAnalyseSetting";
    query.exec(sql);
    while(query.next()){
        islv=query.value("isLv").toString();
    }
    for (int i=0;i<positionList.length();i++) {
        if(islv=="0"){
            sql=getChartQuerySql("FluorescenceLvBoData",positionList[i].value("PositionNumber").toString());
        }else if(islv=="1"){
            sql=getChartQuerySql("FluorescenceData",positionList[i].value("PositionNumber").toString());
        }
        query.exec(sql);

        QList<QVariantMap> resultList;

        while (query.next()) {
            QVariantMap map;
            for (int i = 0; i < query.record().count(); ++i) {
                map[query.record().fieldName(i)] = query.value(i);
            }
            resultList.append(map);
        }

        QList<QString> accessList;
        sql=QString("Select distinct AccessName "
                    "From SampleInfo s "
                    "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                    "Left Join FluorescenceData f on s.Id=f.SampleId "
                    "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
        query.exec(sql);
        QString queryInfo;
        while (query.next()) {
            if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                accessList.append("FAM");
            }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                accessList.append("VIC");
            }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                accessList.append("ROX");
            }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                accessList.append("CY5");
            }
        }

        for(int m=0;m<accessList.count();m++){
            QSplineSeries* line = new QSplineSeries();//光滑曲线;
            allOrigLines.append(line);
            myChart->addSeries(line);//添加曲线
            for (int n=0;n<resultList.length();n++) {

                line->append(QPointF(resultList[n].value("CyclesNumber").toInt(),resultList[n].value(accessList[m]).toReal()));
                if(resultList[n].value(accessList[m]).toReal()>maxY){
                    maxY=(qFloor(resultList[n].value(accessList[m]).toReal()/4000)+1)*4000;
                }
            }

            if(accessList[m]=="FAM"){
                line->setPen(QPen(QColor(66,46,205)));
            }else if(accessList[m]=="ROX"){
                line->setPen(QPen(QColor(255,135,62)));
            }else if (accessList[m]=="CY5") {
                line->setPen(QPen(QColor(255,43,55)));
            }else if(accessList[m]=="VIC"){
                line->setPen(QPen(QColor(0,196,115)));
            }

            line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
            line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
        }
    }


    axisY->setTitleText("荧光强度(Ru)");
    axisY->setRange(0,maxY);
    axisY->setLabelFormat("%.0f");
    if(maxY>20000){
        axisY->setTickCount(maxY/4000+1);
    }else{
        axisY->setTickCount(maxY/2000+1);
    }

    axisX->setTitleText("循环数(Cycles)");
    axisX->setLabelFormat("%.0f");
    axisX->setRange(1,analyseClient->leh);
    axisX->setTickCount(analyseClient->leh/2);

    // 主网格线
    axisX->setGridLineVisible(true);
    axisX->setGridLineColor(Qt::darkGray);
    axisY->setGridLineVisible(true);
    axisY->setGridLineColor(Qt::darkGray);

    QLegend *legend=myChart->legend();
    legend->setVisible(false);//隐藏图例
    ui->graphicsView->setRenderHint(QPainter::RenderHint::Antialiasing);//开启抗锯齿，否则曲线会有毛刺
    ui->graphicsView->setChart(myChart);//将图表放到画布上
}

//刷新原始曲线数据表
void DataAnalysisWindow::refOriginalCurveTable(){
    ui->tableWidget->blockSignals(true);

    ui->tableWidget->setRowCount(0);
    QList<QString> rowInfoList;
    rowInfoList<<""<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料";

    ui->tableWidget->setColumnCount(rowInfoList.length());
    ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
    ui->tableWidget->setColumnHidden(0, true); // 隐藏第1列
    QString queryString;
    if(ui->FAMCheckBox->isChecked()){
        queryString+="'FAM',";
    }
    if(ui->VICCheckBox->isChecked()){
        queryString+="'VIC',";
    }
    if(ui->ROXCheckBox->isChecked()){
        queryString+="'ROX',";
    }
    if(ui->CY5CheckBox->isChecked()){
        queryString+="'CY5',";
    }
    queryString = queryString.left(queryString.length()-1);

    QString queryRuleString;

    if(!anscrui->posInfo.contains("全部"))//孔位
    {
        QList<QString> posList=anscrui->posInfo.split(',');
        QString posInfo;
        for (int i=0;i<posList.length();i++)
        {
            posInfo+="'"+posList[i]+"',";
        }
        posInfo = posInfo.left(posInfo.length()-1);

        queryRuleString.append(QString("and RealPos in (%1) ").arg(posInfo));
    }
    if(anscrui->sampleName !="全部")//样本名
    {
        queryRuleString.append(QString("and sampleName='%1' ").arg(anscrui->sampleName));
    }
    if(anscrui->testType !="全部")//检测类型
    {
        queryRuleString.append(QString("and SampleType='%1' ").arg(anscrui->testType));
    }

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QList<QString> label;
    label<<""<<"RealPos"<<"SampleName"<<"SampleType"<<"AccessName";
    int rowNum=0;

    QString  sql;
    if(isYing){
        sql=QString( "select distinct  "
                     "(select Name from ItemCode where dicCode=5 and Code=PositionNumber) as RealPos,"
                     "SampleName,SampleType,"
                     "sa.AccessName "
                     "from sampleInfo s "
                     "join SampleAccessInfo sa on s.ID = sa.SampleGuid "
                     "Left join FluorescenceData f on s.ID = f.SampleId "
                     "where sa.AccessName in (%1) %2 "
                     "order by PositionNumber,CyclesNumber;").arg(queryString,queryRuleString);
    }else{
        sql=QString( "select distinct  "
                     "(select Name from ItemCode where dicCode=5 and Code=Pos) as RealPos,"
                     "SampleName,SampleType,"
                     "sa.AccessName "
                     "from sampleInfo s "
                     "join SampleAccessInfo sa on s.ID = sa.SampleGuid "
                     "where sa.AccessName in (%1) %2 "
                     "order by Pos;").arg(queryString,queryRuleString);
    }

    query.exec(sql);
    while (query.next()) {
        ui->tableWidget->insertRow(rowNum);
        QTableWidgetItem *item = new QTableWidgetItem(QString::number(rowNum));
        ui->tableWidget->setItem(rowNum, 0, item);
        for(int m=1;m<label.length();m++){
            QTableWidgetItem *item = new QTableWidgetItem(query.value(label[m]).toString());
            ui->tableWidget->setItem(rowNum, m, item);
        }
        rowNum++;
    }
    if(isYing){
        ui->tableWidget->blockSignals(false);
    }

    for(int i=0;i<ui->tableWidget->rowCount();i++){
        ReadOnlyDelegate* readOnlyDelegate = new ReadOnlyDelegate(this);
        ui->tableWidget->setItemDelegateForColumn(i, readOnlyDelegate);
    }
}

//选中表格数据曲线图高亮
void DataAnalysisWindow::on_tableWidget_itemSelectionChanged()
{
    QList<int> rowList;
    rowList.clear();

    if(ui->comboBox->currentText()=="原始曲线"){
        QList<QTableWidgetSelectionRange> selectedItems = ui->tableWidget->selectedRanges();
        foreach(QTableWidgetSelectionRange range,selectedItems){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                rowList.append(j);
                int StepNum=ui->tableWidget->item(j,0)->text().toInt();
                QString AccessName=ui->tableWidget->item(j,4)->text();
                QLineSeries *line= allOrigLines[StepNum];
                QPen highPen;
                highPen.setWidth(4);
                if(AccessName=="FAM"){
                    highPen.setColor(QColor(66,46,205));
                }else if(AccessName=="ROX"){
                    highPen.setColor(QColor(255,135,62));
                }else if(AccessName=="VIC"){
                    highPen.setColor(QColor(0,196,115));
                }else if(AccessName=="CY5"){
                    highPen.setColor(QColor(255,43,55));
                }

                line->setPen(highPen);
            }
        }

        for(int i=0;i<ui->tableWidget->rowCount();i++){
            if(!rowList.contains(i)){
                QString AccessName=ui->tableWidget->item(i,4)->text();
                QLineSeries *line= allOrigLines[i];
                QPen highPen;
                if(AccessName=="FAM"){
                    highPen.setColor(QColor(66,46,205));
                }else if(AccessName=="ROX"){
                    highPen.setColor(QColor(255,135,62));
                }else if(AccessName=="VIC"){
                    highPen.setColor(QColor(0,196,115));
                }else if(AccessName=="CY5"){
                    highPen.setColor(QColor(255,43,55));
                }
                line->setPen(highPen);
            }
        }
    }
    else if(ui->comboBox->currentText()=="扩增曲线")
    {
        QList<QTableWidgetSelectionRange> selectedItems = ui->tableWidget->selectedRanges();
        if(ui->checkBox->isChecked() && !ui->checkBox_2->isChecked() && !ui->checkBox_4->isChecked())//Rn
        {
            foreach(QTableWidgetSelectionRange range,selectedItems)
            {
                for (int j=range.topRow();j<=range.bottomRow();j++)
                {
                    rowList.append(j);
                    int StepNum=ui->tableWidget->item(j,0)->text().toInt();
                    QString AccessName=ui->tableWidget->item(j,4)->text();
                    QLineSeries *line= allRnLines[StepNum];
                    QPen highPen;
                    highPen.setWidth(4);
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

            for(int i=0;i<ui->tableWidget->rowCount();i++){
                if(!rowList.contains(i)){
                    QString AccessName=ui->tableWidget->item(i,4)->text();
                    QLineSeries *line= allRnLines[i];
                    QPen highPen;
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

        }
        if(ui->checkBox_2->isChecked())//归一化
        {
            foreach(QTableWidgetSelectionRange range,selectedItems)
            {
                for (int j=range.topRow();j<=range.bottomRow();j++)
                {
                    rowList.append(j);
                    int StepNum=ui->tableWidget->item(j,0)->text().toInt();
                    QString AccessName=ui->tableWidget->item(j,4)->text();
                    QLineSeries *line= allNormalLines[StepNum];
                    QPen highPen;
                    highPen.setWidth(4);
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

            for(int i=0;i<ui->tableWidget->rowCount();i++){
                if(!rowList.contains(i)){
                    QString AccessName=ui->tableWidget->item(i,4)->text();
                    QLineSeries *line= allNormalLines[i];
                    QPen highPen;
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

        }
        if(ui->checkBox_4->isChecked())//对数
        {
            foreach(QTableWidgetSelectionRange range,selectedItems)
            {
                for (int j=range.topRow();j<=range.bottomRow();j++)
                {
                    rowList.append(j);
                    int StepNum=ui->tableWidget->item(j,0)->text().toInt();
                    QString AccessName=ui->tableWidget->item(j,4)->text();
                    QLineSeries *line= allLogLines[StepNum];
                    QPen highPen;
                    highPen.setWidth(4);
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

            for(int i=0;i<ui->tableWidget->rowCount();i++){
                if(!rowList.contains(i)){
                    QString AccessName=ui->tableWidget->item(i,4)->text();
                    QLineSeries *line= allLogLines[i];
                    QPen highPen;
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

        }
        else //△Rn
        {
            foreach(QTableWidgetSelectionRange range,selectedItems)
            {
                for (int j=range.topRow();j<=range.bottomRow();j++)
                {
                    rowList.append(j);
                    int StepNum=ui->tableWidget->item(j,0)->text().toInt();
                    QString AccessName=ui->tableWidget->item(j,4)->text();
                    QLineSeries *line= allAmplLines[StepNum];
                    QPen highPen;
                    highPen.setWidth(4);
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

            for(int i=0;i<ui->tableWidget->rowCount();i++){
                if(!rowList.contains(i)){
                    QString AccessName=ui->tableWidget->item(i,4)->text();
                    QLineSeries *line= allAmplLines[i];
                    QPen highPen;
                    if(AccessName=="FAM"){
                        highPen.setColor(QColor(66,46,205));
                    }else if(AccessName=="ROX"){
                        highPen.setColor(QColor(255,135,62));
                    }else if(AccessName=="VIC"){
                        highPen.setColor(QColor(0,196,115));
                    }else if(AccessName=="CY5"){
                        highPen.setColor(QColor(255,43,55));
                    }
                    line->setPen(highPen);
                }
            }

        }
    }
    else if(ui->comboBox->currentText()=="标准曲线"){
        QList<QTableWidgetSelectionRange> selectedItems = ui->tableWidget->selectedRanges();
        foreach(QTableWidgetSelectionRange range,selectedItems){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                rowList.append(j);
            }
        }
        for(int i=0;i<rowList.length();i++){
            int timefl=0;
            if(ui->tableWidget->item(i,3)->text()=="标准品"&&ui->tableWidget->item(i,4)->text()=="FAM"){

            }else if(ui->tableWidget->item(i,3)->text()=="标准品"&&ui->tableWidget->item(i,4)->text()=="VIC"){

            }else if(ui->tableWidget->item(i,3)->text()=="标准品"&&ui->tableWidget->item(i,4)->text()=="ROX"){

            }else if(ui->tableWidget->item(i,3)->text()=="标准品"&&ui->tableWidget->item(i,4)->text()=="CY5"){

            }else if(ui->tableWidget->item(i,3)->text()=="未知"&&ui->tableWidget->item(i,4)->text()=="FAM"){

            }else if(ui->tableWidget->item(i,3)->text()=="未知"&&ui->tableWidget->item(i,4)->text()=="VIC"){

            }else if(ui->tableWidget->item(i,3)->text()=="未知"&&ui->tableWidget->item(i,4)->text()=="ROX"){

            }else if(ui->tableWidget->item(i,3)->text()=="未知"&&ui->tableWidget->item(i,4)->text()=="CY5"){

            }
        }
    }
}

//刷新扩增曲线
void DataAnalysisWindow::refAmplificationCurveChart(){
    myChart->removeSeries(fThresholdLine);
    myChart->removeSeries(rThresholdLine);
    myChart->removeSeries(vThresholdLine);
    myChart->removeSeries(cThresholdLine);

    ui->lineEdit->hide();
    ui->lineEdit_2->hide();
    ui->lineEdit_3->hide();
    ui->lineEdit_4->hide();

    myChart = new QChart();
    int maxY=2000;

    if(ui->checkBox->isChecked())//Rn
    {
        if(!ui->checkBox_2->isChecked() && !ui->checkBox_4->isChecked())
        {
            allRnLines.clear();

            axisY = new QValueAxis(myChart);
            axisX = new QValueAxis(myChart);

            myChart->addAxis(axisY,Qt::AlignmentFlag::AlignLeft);//绑定Y轴到图表左侧
            myChart->addAxis(axisX,Qt::AlignmentFlag::AlignBottom);//绑定X轴到图表底部

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            QString sql= GetChartQueryPosition();
            query.exec(sql);
            QList<QVariantMap> positionList;

            while(query.next()){
                QVariantMap map;
                for (int i = 0; i < query.record().count(); ++i) {
                    map[query.record().fieldName(i)] = query.value(i);
                }
                positionList.append(map);
            }
            for(int i=0;i<positionList.length();i++){
                QStringList accessList;
                QString queryString;
                QString sql=QString("Select distinct AccessName "
                                    "From SampleInfo s "
                                    "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                                    "Left Join FluorescenceData f on s.Id=f.SampleId "
                                    "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList<<"FAM";
                        queryString+="FAM+(select BaselineValue from FluorescenceResultTable where f.SampleId=FluorescenceResultTable.SampleID and FluorescenceResultTable.AccessType='FAM') AS FAM,";
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList<<"VIC";
                        queryString+="VIC+(select BaselineValue from FluorescenceResultTable where f.SampleId=FluorescenceResultTable.SampleID and FluorescenceResultTable.AccessType='VIC') AS VIC ,";
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList<<"ROX";
                        queryString+="ROX+(select BaselineValue from FluorescenceResultTable where f.SampleId=FluorescenceResultTable.SampleID and FluorescenceResultTable.AccessType='ROX') AS ROX,";
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList<<"CY5";
                        queryString+="CY5+(select BaselineValue from FluorescenceResultTable where f.SampleId=FluorescenceResultTable.SampleID and FluorescenceResultTable.AccessType='CY5') AS CY5,";
                    }
                }

                queryString = queryString.left(queryString.length()-1);

                sql=QString("select CyclesNumber,%1 "
                            "from sampleInfo s "
                            "Join SampleAccessInfo a on s.id=a.SampleGuid "
                            "Left join FluorescencelvData f on s.ID=f.SampleId "
                            "where PositionNumber='%2' "
                            "order by PositionNumber,CyclesNumber;").arg(queryString,positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QList<QVariantMap> resultList;
                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    myChart->addSeries(line);//添加曲线
                    allRnLines.append(line);
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt(),resultList[n].value(accessList[m]).toReal()));
                        if(resultList[n].value(accessList[m]).toReal()>maxY){
                            maxY=(qFloor(resultList[n].value(accessList[m]).toReal()/4000)+1)*4000;
                        }
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,33,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }

            axisY->setRange(0,maxY);
            axisY->setLabelFormat("%.0f");
            if(maxY>20000){
                axisY->setTickCount(maxY/4000+1);
            }else{
                axisY->setTickCount(maxY/2000+1);
            }
        }
        else if(ui->checkBox_2->isChecked())//归一化
        {
            QStringList accessList;

            axisY = new QValueAxis(myChart);
            axisX = new QValueAxis(myChart);

            myChart->addAxis(axisY,Qt::AlignmentFlag::AlignLeft);//绑定Y轴到图表左侧
            myChart->addAxis(axisX,Qt::AlignmentFlag::AlignBottom);//绑定X轴到图表底部

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            QString sql= GetChartQueryPosition();
            query.exec(sql);
            QList<QVariantMap> positionList;
            while(query.next()){
                QVariantMap map;
                for (int i = 0; i < query.record().count(); ++i) {
                    map[query.record().fieldName(i)] = query.value(i);
                }
                positionList.append(map);
            }

            allNormalLines.clear();
            for(int i=0;i<positionList.length();i++){
                QList<QString> accessList;
                sql=QString("Select distinct AccessName "
                            "From SampleInfo s "
                            "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                            "Left Join FluorescenceData f on s.Id=f.SampleId "
                            "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList.append("FAM");
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList.append("VIC");
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList.append("ROX");
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList.append("CY5");
                    }
                }
                QString sql=getChartQuerySql("FluorescenceNormalData",positionList[i].value("PositionNumber").toString());
                query.exec(sql);

                QList<QVariantMap> resultList;
                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    allNormalLines.append(line);
                    myChart->addSeries(line);//添加曲线
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt( ),resultList[n].value(accessList[m]).toReal()));
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,43,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }

            axisY->setRange(0,1);
            axisY->setTickCount(10);
        }
        else if(ui->checkBox_4->isChecked())//对数
        {
            double minY=5;
            QStringList accessList;

            axisY = new QValueAxis(myChart);
            axisX = new QValueAxis(myChart);

            myChart->addAxis(axisY,Qt::AlignmentFlag::AlignLeft);//绑定Y轴到图表左侧
            myChart->addAxis(axisX,Qt::AlignmentFlag::AlignBottom);//绑定X轴到图表底部

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            QString sql= GetChartQueryPosition();
            query.exec(sql);
            QList<QVariantMap> positionList;
            while(query.next()){
                QVariantMap map;
                for (int i = 0; i < query.record().count(); ++i) {
                    map[query.record().fieldName(i)] = query.value(i);
                }
                positionList.append(map);
            }

            allLogLines.clear();

            for(int i=0;i<positionList.length();i++){

                QList<QString> accessList;
                sql=QString("Select distinct AccessName "
                            "From SampleInfo s "
                            "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                            "Left Join FluorescenceData f on s.Id=f.SampleId "
                            "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList.append("FAM");
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList.append("VIC");
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList.append("ROX");
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList.append("CY5");
                    }
                }

                QString sql=getChartQuerySql("FluorescenceRnLogData",positionList[i].value("PositionNumber").toString());
                query.exec(sql);

                QList<QVariantMap> resultList;
                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    myChart->addSeries(line);//添加曲线
                    allLogLines.append(line);
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt( ),resultList[n].value(accessList[m]).toReal()));
                        if(minY>resultList[n].value(accessList[m]).toReal()){
                            minY=resultList[n].value(accessList[m]).toReal();
                        }
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,43,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }
            axisY->setRange(qRound(minY)-0.5,5);
            axisY->setTickCount(10);
        }

        axisY->setTitleText("荧光强度(Rn)");
    }
    else//△Rn
    {
        QStringList accessList;

        axisY = new QValueAxis(myChart);
        axisX = new QValueAxis(myChart);

        myChart->addAxis(axisY,Qt::AlignmentFlag::AlignLeft);//绑定Y轴到图表左侧
        myChart->addAxis(axisX,Qt::AlignmentFlag::AlignBottom);//绑定X轴到图表底部

        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        QString sql= GetChartQueryPosition();
        query.exec(sql);
        QList<QVariantMap> positionList;
        while(query.next()){
            QVariantMap map;
            for (int i = 0; i < query.record().count(); ++i) {
                map[query.record().fieldName(i)] = query.value(i);
            }
            positionList.append(map);
        }
        if(!ui->checkBox_2->isChecked() && !ui->checkBox_4->isChecked()){
            allAmplLines.clear();
            for(int i=0;i<positionList.length();i++){
                QString sql=getChartQuerySql("FluorescenceLvData",positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QList<QVariantMap> resultList;

                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                QList<QString> accessList;
                sql=QString("Select distinct AccessName "
                            "From SampleInfo s "
                            "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                            "Left Join FluorescenceData f on s.Id=f.SampleId "
                            "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList.append("FAM");
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList.append("VIC");
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList.append("ROX");
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList.append("CY5");
                    }
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    allAmplLines.append(line);
                    myChart->addSeries(line);//添加曲线
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt(),resultList[n].value(accessList[m]).toReal()));
                        line->setName(QString::number(i)+"."+accessList[m]);
                        if(resultList[n].value(accessList[m]).toReal()>maxY){
                            maxY=(qFloor(resultList[n].value(accessList[m]).toReal()/4000)+1)*4000;
                        }
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,43,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }

            axisY->setRange(0,maxY);
            axisY->setLabelFormat("%.0f");
            if(maxY>20000){
                axisY->setTickCount(maxY/4000+1);
            }else{
                axisY->setTickCount(maxY/2000+1);
            }
        }
        else if(ui->checkBox_2->isChecked())//归一化
        {
            allNormalLines.clear();
            for(int i=0;i<positionList.length();i++){
                QString sql=getChartQuerySql("FluorescenceNormalData",positionList[i].value("PositionNumber").toString());
                query.exec(sql);

                QList<QVariantMap> resultList;
                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                QList<QString> accessList;
                sql=QString("Select distinct AccessName "
                            "From SampleInfo s "
                            "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                            "Left Join FluorescenceData f on s.Id=f.SampleId "
                            "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList.append("FAM");
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList.append("VIC");
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList.append("ROX");
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList.append("CY5");
                    }
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    allNormalLines.append(line);
                    myChart->addSeries(line);//添加曲线
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt( ),resultList[n].value(accessList[m]).toReal()));
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,43,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }

            axisY->setRange(0,1);
            axisY->setTickCount(10);

        }
        else if(ui->checkBox_4->isChecked())//对数
        {
            allLogLines.clear();

            for(int i=0;i<positionList.length();i++){
                QString sql=getChartQuerySql("FluorescenceLogData",positionList[i].value("PositionNumber").toString());
                query.exec(sql);

                QList<QVariantMap> resultList;
                while (query.next()) {
                    QVariantMap map;
                    for (int i = 0; i < query.record().count(); ++i) {
                        map[query.record().fieldName(i)] = query.value(i);
                    }
                    resultList.append(map);
                }

                QList<QString> accessList;
                sql=QString("Select distinct AccessName "
                            "From SampleInfo s "
                            "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                            "Left Join FluorescenceData f on s.Id=f.SampleId "
                            "where f.positionNumber=%1").arg(positionList[i].value("PositionNumber").toString());
                query.exec(sql);
                QString queryInfo;
                while (query.next()) {
                    if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
                        accessList.append("FAM");
                    }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
                        accessList.append("VIC");
                    }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
                        accessList.append("ROX");
                    }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
                        accessList.append("CY5");
                    }
                }

                for(int m=0;m<accessList.count();m++){
                    QSplineSeries* line = new QSplineSeries();//光滑曲线
                    myChart->addSeries(line);//添加曲线
                    allLogLines.append(line);
                    for(int n=0;n<resultList.length();n++)
                    {
                        line->append(QPointF(resultList[n].value("CyclesNumber").toInt( ),resultList[n].value(accessList[m]).toReal()));
                    }

                    if(accessList[m]=="FAM"){
                        line->setPen(QPen(QColor(66,46,205)));
                    }else if(accessList[m]=="ROX"){
                        line->setPen(QPen(QColor(255,135,62)));
                    }else if (accessList[m]=="CY5") {
                        line->setPen(QPen(QColor(255,43,55)));
                    }else if(accessList[m]=="VIC"){
                        line->setPen(QPen(QColor(0,196,115)));
                    }

                    line->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                    line->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                }
            }
            axisY->setRange(0,5);
            axisY->setTickCount(10);
        }

        axisY->setTitleText("荧光强度(△Rn)");
    }

    axisX->setLabelFormat("%.0f");
    axisX->setRange(1,analyseClient->leh);
    axisX->setTitleText("循环数(Cycles)");
    axisX->setTickCount(analyseClient->leh/2);

    axisX->setGridLineVisible(true);
    axisX->setGridLineColor(Qt::darkGray);
    axisY->setGridLineVisible(true);
    axisY->setGridLineColor(Qt::darkGray);

    QLegend *legend=myChart->legend();
    legend->setVisible(false);//隐藏图例
    ui->graphicsView->setRenderHint(QPainter::RenderHint::Antialiasing);//开启抗锯齿，否则曲线会有毛刺
    ui->graphicsView->setChart(myChart);//将图表放到画布上

    if(ui->checkBox_3->isChecked())
    {
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        QString yuType;

        QString sql="Select YuType From DataAnalyseSetting";
        query.exec(sql);
        while (query.next()) {
            yuType = query.value("YuType").toString();
        }
        if(yuType=="相对阈值"){
            if(ui->FAMCheckBox->text()==defaultAccess){
                drawRelaThresholdLine("FAM");
                ui->lineEdit->show();
            }
            else if(ui->ROXCheckBox->text()==defaultAccess){
                drawRelaThresholdLine("ROX");
                ui->lineEdit_3->show();

            }
            else if(ui->CY5CheckBox->text()==defaultAccess){
                drawRelaThresholdLine("CY5");
                ui->lineEdit_4->show();
            }
            else if(ui->VICCheckBox->text()==defaultAccess){
                drawRelaThresholdLine("VIC");
                ui->lineEdit_2->show();
            }
            return;
        }else
        {
            ui->lineEdit->show();
            ui->lineEdit_2->show();
            ui->lineEdit_3->show();
            ui->lineEdit_4->show();
            drawThresholdLine();
        }
    }
}

//刷新扩增曲线数据表
void DataAnalysisWindow::refAmplificationCurveTable(){
    if(doutfl==1){
        famcb = ui->FAMCheckBox->checkState();
        viccb = ui->VICCheckBox->checkState();
        roxcb = ui->ROXCheckBox->checkState();
        cy5cb = ui->CY5CheckBox->checkState();
        ui->FAMCheckBox->setChecked(true);
        ui->VICCheckBox->setChecked(true);
        ui->ROXCheckBox->setChecked(true);
        ui->CY5CheckBox->setChecked(true);
    }

    ui->tableWidget->blockSignals(true);

    ui->tableWidget->setRowCount(0);
    QList<QString> rowInfoList;
    rowInfoList<<""<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT值"<<"浓度值";

    ui->tableWidget->setColumnCount(rowInfoList.length());
    ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
    ui->tableWidget->setColumnHidden(6, true); // 隐藏第7列

    QString queryString;
    if(ui->FAMCheckBox->isChecked()){
        queryString+="'FAM',";
    }
    if(ui->VICCheckBox->isChecked()){
        queryString+="'VIC',";
    }
    if(ui->ROXCheckBox->isChecked()){
        queryString+="'ROX',";
    }
    if(ui->CY5CheckBox->isChecked()){
        queryString+="'CY5',";
    }
    queryString = queryString.left(queryString.length()-1);

    QString queryRuleString;


    if(!anscrui->posInfo.contains("全部"))//孔位
    {
        QList<QString> posList=anscrui->posInfo.split(',');
        QString posInfo;
        for (int i=0;i<posList.length();i++)
        {
            posInfo+="'"+posList[i]+"',";
        }
        posInfo = posInfo.left(posInfo.length()-1);

        queryRuleString.append(QString("and RealPos in (%1) ").arg(posInfo));
    }

    if(anscrui->sampleName !="全部")//样本名
    {
        queryRuleString.append(QString("and sampleName='%1' ").arg(anscrui->sampleName));
    }

    if(anscrui->testType !="全部")//检测类型
    {
        queryRuleString.append(QString("and SampleType='%1' ").arg(anscrui->testType));
    }

    QString  sql;
    if(isYing){
        sql=QString("select distinct "
                    "(select Name from ItemCode where dicCode=5 and Code=PositionNumber) as RealPos,"
                    "SampleName,"
                    "SampleType,"
                    "sa.AccessName,sa.CtValue,"
                    "CASE WHEN "
                    "S.SampleType='标准品' then SampleConc "
                    "else '' end as SampleConc "
                    "from sampleInfo s "
                    "join SampleAccessInfo sa on s.ID=sa.SampleGuid "
                    "Left join FluorescenceData f on s.ID=f.SampleId "
                    "where sa.AccessName in (%1) %2 "
                    "order by PositionNumber,CyclesNumber;").arg(queryString,queryRuleString);
    }else{
        sql=QString("select distinct "
                    "(select Name from ItemCode where dicCode=5 and Code=Pos) as RealPos,"
                    "SampleName,"
                    "SampleType,"
                    "sa.AccessName,sa.CtValue,"
                    "CASE WHEN "
                    "S.SampleType='标准品' then SampleConc "
                    "else '' end as SampleConc "
                    "from sampleInfo s "
                    "Join SampleAccessInfo sa on s.ID=sa.SampleGuid "
                    "where sa.AccessName in (%1) %2 "
                    "order by Pos;").arg(queryString,queryRuleString);
    }

    QList<QString> label;
    label<<""<<"RealPos"<<"SampleName"<<"SampleType"<<"AccessName"<<"CtValue"<<"SampleConc";

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.exec(sql);
    int rowNum=0;
    while (query.next()) {
        ui->tableWidget->insertRow(rowNum);
        QTableWidgetItem *item = new QTableWidgetItem(QString::number(rowNum));
        ui->tableWidget->setItem(rowNum, 0, item);
        for (int m=1;m<label.length();m++) {
            QTableWidgetItem *item = new QTableWidgetItem(query.value(label[m]).toString());
            ui->tableWidget->setItem(rowNum, m, item);
        }
        rowNum++;
    }
    if(isYing){
        ui->tableWidget->blockSignals(false);
    }

    for(int i=0;i<ui->tableWidget->rowCount();i++){
        ReadOnlyDelegate* readOnlyDelegate = new ReadOnlyDelegate(this);
        ui->tableWidget->setItemDelegateForColumn(i, readOnlyDelegate);
    }
}

//阈值线
void DataAnalysisWindow::on_checkBox_3_stateChanged(int arg1)
{
    if(ui->comboBox->currentText()=="扩增曲线"){
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

void DataAnalysisWindow::drawRelaThresholdLine(QString accessType){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql;

    if(ui->checkBox_2->isChecked()){
        sql=QString("Select AccessType,max(NormalThreshold) as Threshold  From FluorescenceResultTable "
                    "Where AccessType ='%1' "
                    "group by AccessType").arg(accessType);
    }else{
        if(ui->checkBox->isChecked()){
            if(ui->checkBox_4->isChecked()){
                sql=QString("Select AccessType,max(RnLogThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType ='%1' "
                            "group by AccessType").arg(accessType);
            }else{
                sql=QString("Select AccessType,max(RnThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType ='%1' "
                            "group by AccessType").arg(accessType);
            }

        }
        else
        {
            if(ui->checkBox_4->isChecked()){
                sql=QString("Select AccessType,max(LogThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType ='%1' "
                            "group by AccessType").arg(accessType);
            }else{
                sql=QString("Select AccessType,max(Threshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType ='%1' "
                            "group by AccessType").arg(accessType);
            }
        }
    }


    query.exec(sql);
    double threshold;
    while (query.next()) {
        threshold=query.value("Threshold").toDouble();
        if(!std::isnan(threshold) && !std::isinf(threshold) && threshold != 0.0){
            if(query.value("AccessType").toString()=="FAM"){
                fThresholdLine=new QLineSeries();
                myChart->addSeries(fThresholdLine);
                fThresholdLine->append(QPointF(0,threshold));
                fThresholdLine->append(QPointF(analyseClient->leh,threshold));
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(66,46,205));
                fThresholdLine->setPen(highPen);
                fThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                fThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                ui->lineEdit->setText(QString::number(threshold,'f',2));
                refCtValue("FAM",threshold);
            }
            if(query.value("AccessType").toString()=="ROX"){
                rThresholdLine=new QLineSeries();
                myChart->addSeries(rThresholdLine);

                rThresholdLine->setPen(QPen(QColor(0,196,115)));
                rThresholdLine->append(QPointF(0,threshold));
                rThresholdLine->append(QPointF(analyseClient->leh,threshold));
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(255,135,62));
                rThresholdLine->setPen(highPen);

                rThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                rThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准
                ui->lineEdit_3->setText(QString::number(threshold,'f',2));

                refCtValue("ROX",threshold);
            }
            if(query.value("AccessType").toString()=="VIC"){
                vThresholdLine=new QLineSeries();
                myChart->addSeries(vThresholdLine);

                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(0,196,115));
                vThresholdLine->setPen(highPen);
                vThresholdLine->append(QPointF(0,threshold));
                vThresholdLine->append(QPointF(analyseClient->leh,threshold));

                vThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                vThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit_2->setText(QString::number(threshold,'f',2));
                refCtValue("VIC",threshold);
            }
            if(query.value("AccessType").toString()=="CY5"){
                cThresholdLine=new QLineSeries();
                myChart->addSeries(cThresholdLine);

                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(255,43,55));
                cThresholdLine->setPen(highPen);
                cThresholdLine->append(QPointF(0,threshold));
                cThresholdLine->append(QPointF(analyseClient->leh,threshold));

                cThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                cThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit_4->setText(QString::number(threshold,'f',2));
                refCtValue("CY5",threshold);
            }
        }
    }

}

//绘制阈值线
void DataAnalysisWindow::drawThresholdLine(){
    QString sql;
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString queryString;

    if(ui->FAMCheckBox->isChecked()){
        queryString+="'FAM',";
        ui->lineEdit->show();
    }
    else
    {
        ui->lineEdit->hide();
    }

    if(ui->ROXCheckBox->isChecked()){
        queryString+="'ROX',";
        ui->lineEdit_3->show();
    }
    else
    {
        ui->lineEdit_3->hide();
    }

    if(ui->VICCheckBox->isChecked()){
        queryString+="'VIC',";
        ui->lineEdit_2->show();
    }
    else
    {
        ui->lineEdit_2->hide();
    }

    if(ui->CY5CheckBox->isChecked()){
        queryString+="'CY5',";
        ui->lineEdit_4->show();
    }
    else{
        ui->lineEdit_4->hide();
    }

    queryString = queryString.left(queryString.length()-1);
    if(ui->checkBox_2->isChecked()){
        sql=QString("Select AccessType,max(NormalThreshold) as Threshold  From FluorescenceResultTable "
                    "Where AccessType in (%1) "
                    "group by AccessType").arg(queryString);
    }
    else{
        if(ui->checkBox->isChecked()){
            if(ui->checkBox_4->isChecked()){
                sql=QString("Select AccessType,max(RnLogThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType in (%1) "
                            "group by AccessType").arg(queryString);
            }else{
                sql=QString("Select AccessType,max(RnThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType in (%1) "
                            "group by AccessType").arg(queryString);
            }

        }
        else
        {
            if(ui->checkBox_4->isChecked()){
                sql=QString("Select AccessType,max(LogThreshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType in (%1) "
                            "group by AccessType").arg(queryString);
            }else{
                sql=QString("Select AccessType,max(Threshold) as Threshold  From FluorescenceResultTable "
                            "Where AccessType in (%1) "
                            "group by AccessType").arg(queryString);
            }
        }
    }

    query.exec(sql);

    double threshold;
    while (query.next()) {
        threshold=query.value("Threshold").toDouble();
        if(!std::isnan(threshold) && !std::isinf(threshold)){
            if(query.value("AccessType").toString()=="FAM"){
                myChart->addSeries(fThresholdLine);

                fThresholdLine->clear();
                fThresholdLine->append(QPointF(0,threshold));
                fThresholdLine->append(QPointF(analyseClient->leh,threshold));
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(66,46,205));
                fThresholdLine->setPen(highPen);
                fThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                fThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit->setText(QString::number(threshold,'f',2));
                refCtValue("FAM",threshold);
            }
            if(query.value("AccessType").toString()=="ROX"){
                myChart->addSeries(rThresholdLine);

                rThresholdLine->clear();
                rThresholdLine->setPen(QPen(QColor(0,196,115)));
                rThresholdLine->append(QPointF(0,threshold));
                rThresholdLine->append(QPointF(analyseClient->leh,threshold));
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(255,135,62));
                rThresholdLine->setPen(highPen);

                rThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                rThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit_3->setText(QString::number(threshold,'f',2));

                refCtValue("ROX",threshold);
            }
            if(query.value("AccessType").toString()=="VIC"){
                myChart->addSeries(vThresholdLine);

                vThresholdLine->clear();
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(0,196,115));
                vThresholdLine->setPen(highPen);
                vThresholdLine->append(QPointF(0,threshold));
                vThresholdLine->append(QPointF(analyseClient->leh,threshold));

                vThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                vThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit_2->setText(QString::number(threshold,'f',2));
                refCtValue("VIC",threshold);
            }
            if(query.value("AccessType").toString()=="CY5"){
                myChart->addSeries(cThresholdLine);
                cThresholdLine->clear();
                QPen highPen;
                highPen.setWidth(4);
                highPen.setColor(QColor(255,43,55));
                cThresholdLine->setPen(highPen);
                cThresholdLine->append(QPointF(0,threshold));
                cThresholdLine->append(QPointF(analyseClient->leh,threshold));

                cThresholdLine->attachAxis(axisX);//曲线绑定到X轴，必须在坐标轴绑定刻度之后，否则图像不准
                cThresholdLine->attachAxis(axisY);//曲线绑定到Y轴，必须在坐标轴绑定刻度之后，否则图像不准

                ui->lineEdit_4->setText(QString::number(threshold,'f',2));
                refCtValue("CY5",threshold);
            }
        }
    }
}

void DataAnalysisWindow::on_lineEdit_editingFinished()
{
    double newNum=ui->lineEdit->text().toDouble();
    refCtValue("FAM",newNum);
    refAmplificationCurveTable();
    refAmplificationCurveChart();
}

void DataAnalysisWindow::on_lineEdit_2_editingFinished()
{
    double newNum=ui->lineEdit_2->text().toDouble();
    refCtValue("VIC",newNum);
    refAmplificationCurveTable();
    refAmplificationCurveChart();
}

void DataAnalysisWindow::on_lineEdit_3_editingFinished()
{
    double newNum=ui->lineEdit_3->text().toDouble();
    refCtValue("ROX",newNum);
    refAmplificationCurveTable();
    refAmplificationCurveChart();
}

void DataAnalysisWindow::on_lineEdit_4_editingFinished()
{
    double newNum=ui->lineEdit_4->text().toDouble();
    refCtValue("CY5",newNum);
    refAmplificationCurveTable();
    refAmplificationCurveChart();
}

void DataAnalysisWindow::refCtValue(QString access,double newBaseVal){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    db.transaction();

    QString sql;
    if(ui->checkBox_2->isChecked()){
        sql= QString("Update FluorescenceResultTable set NormalThreshold='%1' where AccessType='%2'").arg(QString::number(newBaseVal),access);
        query.exec(sql);
    }
    else{
        if(ui->checkBox->isChecked()){
            if(ui->checkBox_4->isChecked()){
                sql= QString("Update FluorescenceResultTable set RnLogThreshold='%1' where AccessType='%2'").arg(QString::number(newBaseVal),access);
                query.exec(sql);
            }else{
                sql= QString("Update FluorescenceResultTable set RnThreshold='%1' where AccessType='%2'").arg(QString::number(newBaseVal),access);
                query.exec(sql);
            }

        }
        else{
            if(ui->checkBox_4->isChecked()){
                sql= QString("Update FluorescenceResultTable set LogThreshold='%1' where AccessType='%2'").arg(QString::number(newBaseVal),access);
                query.exec(sql);
            }else{
                sql= QString("Update FluorescenceResultTable set Threshold='%1' where AccessType='%2'").arg(QString::number(newBaseVal),access);
                query.exec(sql);
            }
        }
    }

    for(int i=1;i<=MainWindow::HoleNum;i++){
        QString  sql=QString("select f.sampleId,%1 "
                             "From FluorescenceData f "
                             "where PositionNumber='%2' "
                             "order by CyclesNumber;").arg(access,QString::number(i));
        query.exec(sql);

        QVector<QPointF> data;
        QString sampleId;
        int num=1;
        while (query.next()) {
            sampleId = query.value("sampleId").toString();
            data.append(QPointF(num,query.value(access).toInt()));
            num++;
        }

        QPCRModel::Model *sigmoid;
        sigmoid=new QPCRModel::Model();
        QString ctVal;

        sigmoid->setRawData(data);
        sigmoid->startCalculation();
        double ct = 0;

        if(ui->checkBox_2->isChecked()){
            QPCRModel::Model::YAxisType axisType=static_cast<QPCRModel::Model::YAxisType>(4);
            ct = sigmoid->getCt(newBaseVal,axisType);
        }else{
            if(ui->checkBox->isChecked())//Rn
            {
                if(ui->checkBox_4->isChecked()){
                    QPCRModel::Model::YAxisType axisType=static_cast<QPCRModel::Model::YAxisType>(2);
                    ct = sigmoid->getCt(newBaseVal,axisType);
                }else{
                    QPCRModel::Model::YAxisType axisType=static_cast<QPCRModel::Model::YAxisType>(0);
                    ct = sigmoid->getCt(newBaseVal,axisType);
                }
            }
            else
            {
                if(ui->checkBox_4->isChecked()){
                    QPCRModel::Model::YAxisType axisType=static_cast<QPCRModel::Model::YAxisType>(3);
                    ct = sigmoid->getCt(newBaseVal,axisType);
                }else{
                    QPCRModel::Model::YAxisType axisType=static_cast<QPCRModel::Model::YAxisType>(1);
                    ct = sigmoid->getCt(newBaseVal,axisType);
                }
            }
        }


        if(ct<1 || ct>analyseClient->leh)
        {
            ctVal="nan";
        }
        else
        {
            ctVal=QString::number(ct,'f',2);
        }
        sql= QString("Update SampleAccessInfo set CtValue='%1' where AccessName='%2' and SampleGuid='%3'").arg(ctVal,access,sampleId);
        query.exec(sql);

        sql= QString("Update FluorescenceResultTable set CTVal='%1' where AccessType='%2' and SampleID='%3'").arg(ctVal,access,sampleId);
        query.exec(sql);

    }

    db.commit();
}

//归一化
void DataAnalysisWindow::on_checkBox_2_stateChanged(int arg1)
{
    if(ui->comboBox->currentText()=="扩增曲线"){
        if(arg1==2){
            if(ui->checkBox_4->isChecked()){
                ui->checkBox_4->setChecked(false);
            }
        }
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

void DataAnalysisWindow::on_checkBox_4_stateChanged(int arg1)
{
    if(ui->comboBox->currentText()=="扩增曲线"){
        if(arg1==2 && ui->checkBox_2->isChecked()){
            ui->checkBox_2->setChecked(false);
        }
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

void DataAnalysisWindow::on_checkBox_stateChanged(int arg1)
{
    if(ui->comboBox->currentText()=="扩增曲线"){
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

QString DataAnalysisWindow::getChartQuerySql(QString queryTable,QString PositionNumber){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("Select distinct AccessName "
                        "From SampleInfo s "
                        "Join SampleAccessInfo a on s.Id=a.SampleGuid "
                        "Left Join FluorescenceData f on s.Id=f.SampleId "
                        "where f.positionNumber=%1").arg(PositionNumber);
    query.exec(sql);
    QString queryInfo;
    while (query.next()) {
        if(query.value("AccessName").toString()=="FAM"&&ui->FAMCheckBox->isChecked()){
            queryInfo+="FAM,";
        }else if(query.value("AccessName").toString()=="VIC"&&ui->VICCheckBox->isChecked()){
            queryInfo+="VIC,";
        }else if(query.value("AccessName").toString()=="ROX"&&ui->ROXCheckBox->isChecked()){
            queryInfo+="ROX,";
        }else if(query.value("AccessName").toString()=="CY5"&&ui->CY5CheckBox->isChecked()){
            queryInfo+="CY5,";
        }
    }
    queryInfo = queryInfo.left(queryInfo.length()-1);

    sql=QString("select CyclesNumber,%1 "
                "from  %2 f "
                "where PositionNumber='%3' "
                "order by PositionNumber,CyclesNumber;").arg(queryInfo,queryTable,PositionNumber);
    return  sql;
}

QString DataAnalysisWindow::GetChartQueryPosition(){
    QString queryRuleString;
    if(!anscrui->posInfo.contains("全部"))//孔位
    {
        QList<QString> posList=anscrui->posInfo.split(',');
        QString posInfo;
        for (int i=0;i<posList.length();i++)
        {
            posInfo+="'"+posList[i]+"',";
        }
        posInfo = posInfo.left(posInfo.length()-1);

        queryRuleString.append(QString(" and f.positionNumber in(Select Code from ItemCode where Name in(%1) and dicCode=5) ").arg(posInfo));
    }
    if(anscrui->sampleName !="全部")//样本名
    {
        queryRuleString.append(QString("and s.sampleName='%1' ").arg(anscrui->sampleName ));
    }

    if(anscrui->testType !="全部")//检测类型
    {
        queryRuleString.append(QString("and s.SampleType='%1' ").arg(anscrui->testType ));
    }

    QString sql=QString("SELECT distinct PositionNumber "
                        "FROM SampleInfo s "
                        "Join SampleAccessInfo a on s.id=a.SampleGuid "
                        "Left join FluorescenceData f on s.id=f.sampleid "
                        "where 1=1 %1  "
                        "order by f.PositionNumber").arg(queryRuleString);
    return  sql;

}

//FAM 点击事件
void DataAnalysisWindow::on_FAMCheckBox_clicked()
{
    if(ui->comboBox->currentText()=="原始曲线"){
        refOriginalCurveChart();
        refOriginalCurveTable();
    }
    else if (ui->comboBox->currentText()=="扩增曲线") {
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

//VIC 点击事件
void DataAnalysisWindow::on_VICCheckBox_clicked()
{
    if(ui->comboBox->currentText()=="原始曲线"){
        refOriginalCurveChart();
        refOriginalCurveTable();
    }
    else if (ui->comboBox->currentText()=="扩增曲线") {
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

//ROX 点击事件
void DataAnalysisWindow::on_ROXCheckBox_clicked()
{
    if(ui->comboBox->currentText()=="原始曲线"){
        refOriginalCurveChart();
        refOriginalCurveTable();
    }
    else if (ui->comboBox->currentText()=="扩增曲线") {
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

//CY5 点击事件
void DataAnalysisWindow::on_CY5CheckBox_clicked()
{
    if(ui->comboBox->currentText()=="原始曲线"){
        refOriginalCurveChart();
        refOriginalCurveTable();
    }
    else if (ui->comboBox->currentText()=="扩增曲线") {
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }
}

// 标准曲线初始化
void DataAnalysisWindow::standardCurveChart()
{
    QString sql="Select count(*) as Num From SampleInfo where SampleType='标准品'";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.exec(sql);
    while (query.next()) {
        MainWindow::isBzsy=query.value("Num")>0;
    }
    qDebug()<<MainWindow::isBzsy;
    if(MainWindow::isBzsy){
        bzsum=0;
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            if(ui->tableWidget->item(i,3)->text()=="标准品"){
                bzsum+=1;
            }
        }
        myChart = new QChart();
        bzROX = new QLineSeries();
        bzVIC = new QLineSeries();
        bzFAM = new QLineSeries();
        bzCY5 = new QLineSeries();
        bzsdROX = new QScatterSeries();
        bzsdVIC = new QScatterSeries();
        bzsdFAM = new QScatterSeries();
        bzsdCY5 = new QScatterSeries();
        fbzROX = new QScatterSeries();
        fbzVIC = new QScatterSeries();
        fbzFAM = new QScatterSeries();
        fbzCY5 = new QScatterSeries();
        QValueAxis *m_axisX = new QValueAxis();
        QValueAxis *m_axisY = new QValueAxis();
        m_axisX->setTickCount(5);
        m_axisY->setTickCount(8);
        m_axisX->setMin(-5);
        m_axisY->setMin(5);
        m_axisX->setMax(10);
        m_axisY->setMax(45);
        // 主网格线
        m_axisX->setGridLineVisible(true);
        m_axisX->setGridLineColor(Qt::darkGray);
        m_axisY->setGridLineVisible(true);
        m_axisY->setGridLineColor(Qt::darkGray);
        myChart->addAxis(m_axisX, Qt::AlignBottom);                      // 将X轴添加到图表上
        myChart->addAxis(m_axisY, Qt::AlignLeft);                    // 将Y轴添加到图表上
        myChart->axisX()->setTitleText("浓度");
        myChart->axisY()->setTitleText("CT值");
        QVector<double> xrox,yrox,yvic,yfam,ycy5;
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if(ui->tableWidget->item(i,3)->text()=="标准品"){
                xrox.append(ui->tableWidget->item(i+1,6)->text().toDouble());
                yrox.append(ui->tableWidget->item(i+1,5)->text().toDouble());
                yvic.append(ui->tableWidget->item(i+2,5)->text().toDouble());
                yfam.append(ui->tableWidget->item(i,5)->text().toDouble());
                ycy5.append(ui->tableWidget->item(i+3,5)->text().toDouble());
            }
        }

        QVector<double> logxrox=logvalue(xrox);
        // 线性回归计算

        calculateLinearRegression(xrox, yrox, krox, brox, r2rox, curox);
        calculateLinearRegression(xrox, yvic, kvic, bvic, r2vic, cuvic);
        calculateLinearRegression(xrox, yfam, kfam, bfam, r2fam, cufam);
        calculateLinearRegression(xrox, ycy5, kcy5, bcy5, r2cy5, cucy5);

        QPen pen;
        pen.setColor(QColor(255,165,0));
        pen.setWidth(2);
        bzROX->setPen(pen);
        bzsdROX->setPen(pen);
        fbzROX->setPen(pen);
        QBrush brush; // 设置填充颜色
        brush.setColor(QColor(255,165,0));
        bzsdROX->setBrush(brush);
        fbzROX->setBrush(brush);

        pen.setColor(QColor(Qt::green));
        pen.setWidth(2);
        bzVIC->setPen(pen);
        bzsdVIC->setPen(pen);
        fbzVIC->setPen(pen);
        brush.setColor(QColor(Qt::green));
        bzsdVIC->setBrush(brush);
        fbzVIC->setBrush(brush);

        pen.setColor(QColor(Qt::blue));
        pen.setWidth(2);
        bzFAM->setPen(pen);
        bzsdFAM->setPen(pen);
        fbzFAM->setPen(pen);
        brush.setColor(QColor(Qt::blue));
        bzsdFAM->setBrush(brush);
        fbzFAM->setBrush(brush);

        pen.setColor(QColor(Qt::red));
        pen.setWidth(2);
        bzCY5->setPen(pen);
        bzsdCY5->setPen(pen);
        fbzCY5->setPen(pen);
        brush.setColor(QColor(Qt::red));
        bzsdCY5->setBrush(brush);
        fbzCY5->setBrush(brush);

        bzsdROX->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeCircle);
        bzsdROX->setMarkerSize(15);
        bzsdVIC->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeCircle);
        bzsdVIC->setMarkerSize(15);
        bzsdFAM->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeCircle);
        bzsdFAM->setMarkerSize(15);
        bzsdCY5->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeCircle);
        bzsdCY5->setMarkerSize(15);
        fbzROX->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeRectangle);
        fbzROX->setMarkerSize(15);
        fbzVIC->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeRectangle);
        fbzVIC->setMarkerSize(15);
        fbzFAM->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeRectangle);
        fbzFAM->setMarkerSize(15);
        fbzCY5->setMarkerShape(QScatterSeries::MarkerShape::MarkerShapeRectangle);
        fbzCY5->setMarkerSize(15);

        myChart->addSeries(bzROX);
        myChart->addSeries(bzVIC);
        myChart->addSeries(bzFAM);
        myChart->addSeries(bzCY5);
        myChart->addSeries(bzsdROX);
        myChart->addSeries(bzsdVIC);
        myChart->addSeries(bzsdFAM);
        myChart->addSeries(bzsdCY5);
        myChart->addSeries(fbzROX);
        myChart->addSeries(fbzVIC);
        myChart->addSeries(fbzFAM);
        myChart->addSeries(fbzCY5);

        bzROX->attachAxis(m_axisX);
        bzROX->attachAxis(m_axisY);
        bzVIC->attachAxis(m_axisX);
        bzVIC->attachAxis(m_axisY);
        bzFAM->attachAxis(m_axisX);
        bzFAM->attachAxis(m_axisY);
        bzCY5->attachAxis(m_axisX);
        bzCY5->attachAxis(m_axisY);
        bzsdROX->attachAxis(m_axisX);
        bzsdROX->attachAxis(m_axisY);
        bzsdVIC->attachAxis(m_axisX);
        bzsdVIC->attachAxis(m_axisY);
        bzsdFAM->attachAxis(m_axisX);
        bzsdFAM->attachAxis(m_axisY);
        bzsdCY5->attachAxis(m_axisX);
        bzsdCY5->attachAxis(m_axisY);
        fbzROX->attachAxis(m_axisX);
        fbzROX->attachAxis(m_axisY);
        fbzVIC->attachAxis(m_axisX);
        fbzVIC->attachAxis(m_axisY);
        fbzFAM->attachAxis(m_axisX);
        fbzFAM->attachAxis(m_axisY);
        fbzCY5->attachAxis(m_axisX);
        fbzCY5->attachAxis(m_axisY);

        QLegend *legend = myChart->legend();
        if (legend) {
            // 获取图例标记数组
            QList<QLegendMarker*> markers = legend->markers();
            if (!markers.isEmpty()) {
                // 隐藏第一个系列的图例项
                for(int i=4;i<12;i++){
                    markers[i]->setVisible(false);
                }
            }
        }
        legend->detachFromChart();

        myChart->setMargins(QMargins(0, 0, 0, 160));

        myChart->legend()->setGeometry(QRectF(50,ui->graphicsView->height()-160,500,160));

        myChart->setAnimationOptions(QChart::SeriesAnimations);        // 动画：能使曲线绘制显示的更平滑，过渡效果更好看
        ui->graphicsView->setChart(myChart);                           // 将图表对象设置到graphicsView上进行显示
        ui->graphicsView->setRenderHint(QPainter::Antialiasing);       // 设置渲染：抗锯齿，如果不设置那么曲线就显得不平滑
        bzFAM->append(QPointF(-10,kfam*(-10)+bfam));
        bzFAM->append(QPointF(10,kfam*10+bfam));
        bzVIC->append(QPointF(-10,kvic*(-10)+bvic));
        bzVIC->append(QPointF(10,kvic*10+bvic));
        bzROX->append(QPointF(-10,krox*(-10)+brox));
        bzROX->append(QPointF(10,krox*10+brox));
        bzCY5->append(QPointF(-10,kcy5*(-10)+bcy5));
        bzCY5->append(QPointF(10,kcy5*10+bcy5));
        qDebug()<<logxrox<<xrox<<yrox;
        for(int i =0;i<xrox.length();i++){
            bzsdROX->append(logxrox[i],yrox[i]);
            bzsdVIC->append(logxrox[i],yvic[i]);
            bzsdFAM->append(logxrox[i],yfam[i]);
            bzsdCY5->append(logxrox[i],ycy5[i]);
        }
        QVector<double> fbzfdata1,fbzvdata1,fbzrdata1,fbzcdata1;
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if(ui->tableWidget->item(i,3)->text()!="标准品"){
                fbzfdata1.append(ui->tableWidget->item(i,5)->text().toDouble());
                fbzvdata1.append(ui->tableWidget->item(i+2,5)->text().toDouble());
                fbzrdata1.append(ui->tableWidget->item(i+1,5)->text().toDouble());
                fbzcdata1.append(ui->tableWidget->item(i+3,5)->text().toDouble());
            }
        }
        double fbzfdata[fbzfdata1.length()],fbzvdata[fbzfdata1.length()],fbzrdata[fbzfdata1.length()],fbzcdata[fbzfdata1.length()];
        for (int i = 0; i < fbzfdata1.length(); ++i) {
            fbzfdata[i] = fbzfdata1[i];
            fbzvdata[i] = fbzvdata1[i];
            fbzrdata[i] = fbzrdata1[i];
            fbzcdata[i] = fbzcdata1[i];
        }

        Analyse analyse;
        analyse.standardK=kfam;
        analyse.standardYInt=bfam;
        std::vector<double> fbzfn10=analyse.Concentration(fbzfdata,ui->tableWidget->rowCount()/4-bzsum/4);
        analyse.standardK=kvic;
        analyse.standardYInt=bvic;
        std::vector<double> fbzvn10=analyse.Concentration(fbzvdata,ui->tableWidget->rowCount()/4-bzsum/4);
        analyse.standardK=krox;
        analyse.standardYInt=brox;
        std::vector<double> fbzrn10=analyse.Concentration(fbzrdata,ui->tableWidget->rowCount()/4-bzsum/4);
        analyse.standardK=kcy5;
        analyse.standardYInt=bcy5;
        std::vector<double> fbzcn10=analyse.Concentration(fbzcdata,ui->tableWidget->rowCount()/4-bzsum/4);
        // 非标准品浓度10计算
        QVector<double> fbzfn,fbzvn,fbzrn,fbzcn;
        for(int i=0;i<fbzfn10.size();i++){
            fbzfn.append(pow(10,fbzfn10[i]));
            fbzvn.append(pow(10,fbzvn10[i]));
            fbzrn.append(pow(10,fbzrn10[i]));
            fbzcn.append(pow(10,fbzcn10[i]));
        }
        // 非标准品散点展示
        for(int i =0;i<fbzfn10.size();i++){
            fbzROX->append(fbzrn10[i],fbzrdata[i]);
            fbzVIC->append(fbzvn10[i],fbzvdata[i]);
            fbzFAM->append(fbzfn10[i],fbzfdata[i]);
            fbzCY5->append(fbzcn10[i],fbzcdata[i]);
        }
        QVector<double> fbznj;
        // 非标准品浓度平均值计算
        for(int i =0;i<fbzfn10.size();i++){
            fbznj.append((fbzfn[i]+fbzvn[i]+fbzrn[i])/3);
        }

        QStringList rowInfoList;
        rowInfoList<<""<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT值"<<"浓度"<<"浓度均值";
        ui->tableWidget->setColumnCount(rowInfoList.length());
        ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
        ui->tableWidget->resizeColumnsToContents(); //根据内容调整列宽
        ui->tableWidget->setColumnHidden(0, true);
        ui->tableWidget->setColumnHidden(6, false);


        int fbznum=0;
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if(ui->tableWidget->item(i,3)->text()!="标准品"){
                QString stcn= QString::number(fbzcn[fbznum],'f',2);
                QString stfn= QString::number(fbzfn[fbznum],'f',2);
                QString strn= QString::number(fbzrn[fbznum],'f',2);
                QString stvn= QString::number(fbzvn[fbznum],'f',2);
                //
                QString stctcn= QString::number(fbzcdata1[fbznum],'f',2);
                QString stctfn= QString::number(fbzfdata1[fbznum],'f',2);
                QString stctrn= QString::number(fbzrdata1[fbznum],'f',2);
                QString stctvn= QString::number(fbzvdata1[fbznum],'f',2);
                // 表格浓度
                if(stfn=="inf"){
                    ui->tableWidget->setItem(i,6,new QTableWidgetItem("nan"));
                }else{
                    ui->tableWidget->setItem(i,6,new QTableWidgetItem(stfn));
                }
                if(strn=="inf"){
                    ui->tableWidget->setItem(i+1,6,new QTableWidgetItem("nan"));
                }else{
                    ui->tableWidget->setItem(i+1,6,new QTableWidgetItem(strn));
                }
                if(stvn=="inf"){
                    ui->tableWidget->setItem(i+2,6,new QTableWidgetItem("nan"));
                }else{
                    ui->tableWidget->setItem(i+2,6,new QTableWidgetItem(stvn));
                }
                if(stcn=="inf"){
                    ui->tableWidget->setItem(i+3,6,new QTableWidgetItem("nan"));
                }else{
                    ui->tableWidget->setItem(i+3,6,new QTableWidgetItem(stcn));
                }
                // 表格ct
                ui->tableWidget->setItem(i,5,new QTableWidgetItem(stctfn));
                ui->tableWidget->setItem(i+1,5,new QTableWidgetItem(stctrn));
                ui->tableWidget->setItem(i+2,5,new QTableWidgetItem(stctvn));
                ui->tableWidget->setItem(i+3,5,new QTableWidgetItem(stctcn));
                // 平均浓度
                for(int k=0;k<4;k++){
                    QString stjn= QString::number(fbznj[fbznum],'f',2);
                    if(stjn=="inf"){
                        ui->tableWidget->setItem(i+k,7,new QTableWidgetItem("nan"));
                    }else{
                        ui->tableWidget->setItem(i+k,7,new QTableWidgetItem(stjn));
                    }
                }
                fbznum++;
            }else{
                for(int k=0;k<4;k++){
                    ui->tableWidget->setItem(i+k,7,new QTableWidgetItem(ui->tableWidget->item(i,6)->text()));
                }
            }

        }
        bzFAM->setName("FAM E="+QString::number(cufam,'f',2)+"%"+" R²="+QString::number(r2fam,'f',2)+" K="+QString::number(kfam,'f',2)+" y-int="+QString::number(bfam,'f',2));
        bzVIC->setName("VIC E="+QString::number(cuvic,'f',2)+"%"+" R²="+QString::number(r2vic,'f',2)+" K="+QString::number(kvic,'f',2)+" y-int="+QString::number(bvic,'f',2));
        bzROX->setName("ROX E="+QString::number(curox,'f',2)+"%"+" R²="+QString::number(r2rox,'f',2)+" K="+QString::number(krox,'f',2)+" y-int="+QString::number(brox,'f',2));
        bzCY5->setName("CY5 E="+QString::number(cucy5,'f',2)+"%"+" R²="+QString::number(r2cy5,'f',2)+" K="+QString::number(kcy5,'f',2)+" y-int="+QString::number(bcy5,'f',2));
        ui->label_2->setText("Y 扩增效率="+QString::number(cufam,'f',2)+"%"+" 斜率="+QString::number(kfam,'f',2)+" R²="+QString::number(r2fam,'f',2)+" Y轴截距="+QString::number(bfam,'f',2));
        ui->label_3->setText("AS 扩增效率="+QString::number(cuvic,'f',2)+"%"+" 斜率="+QString::number(kvic,'f',2)+" R²="+QString::number(r2vic,'f',2)+" Y轴截距="+QString::number(bvic,'f',2));
        ui->label_4->setText("AL 扩增效率="+QString::number(curox,'f',2)+"%"+" 斜率="+QString::number(krox,'f',2)+" R²="+QString::number(r2rox,'f',2)+" Y轴截距="+QString::number(brox,'f',2));
        ui->label_5->setText("");
        if(ui->tableWidget->rowCount()>0){
            qut.clear();
        }
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            qut.append(ui->tableWidget->item(i,7)->text());
        }
    }else {
        QStringList rowInfoList;
        rowInfoList<<""<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT值"<<"浓度"<<"浓度均值";
        ui->tableWidget->setColumnCount(rowInfoList.length());
        ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
        ui->tableWidget->resizeColumnsToContents(); //根据内容调整列宽
        ui->tableWidget->setColumnHidden(0, true);
        ui->tableWidget->setColumnHidden(6, false);
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            ui->tableWidget->setItem(i,6,new QTableWidgetItem(" "));
            ui->tableWidget->setItem(i,7,new QTableWidgetItem(" "));
        }
        myChart = new QChart();
        ui->graphicsView->setChart(myChart);
    }

}

// 标准曲线值计算
void DataAnalysisWindow::calculateLinearRegression(const QVector<double> &x, const QVector<double> &y, double &k, double &b, double &rSquared,double &cubeRoot)
{
    // 对x值取对数
    QVector<double> logx;
    for (double value : x) {
        if (value > 0) { // 确保不会对0或负数取对数
            logx.push_back(std::log10(value)); // 使用以10为底的对数
        } else {
            // 处理0或负数的情况，例如跳过或设置一个默认值
        }
    }
    int n = logx.size();
    if (n != y.size()) {
        qWarning("X and Y data sizes do not match!");
        return;
    }

    double sumX = 0.0, sumY = 0.0, sumXY = 0.0, sumX2 = 0.0;
    for (int i = 0; i < n; ++i){
        sumX += logx[i];
        sumY += y[i];
        sumXY += logx[i] * y[i];
        sumX2 += logx[i] * logx[i];
    }

    double meanX = sumX / n;
    double meanY = sumY / n;
    k = (n * sumXY - sumX * sumY)/(n * sumX2 - sumX * sumX);
    b = meanY - k * meanX;
    double sumResidualsSquared = 0.0;
    double sumYSquared = 0.0;
    for (int i = 0; i < n; ++i) {
        double residual = y[i] - (k * logx[i] + b);
        sumResidualsSquared += residual * residual;
        sumYSquared += y[i] * y[i];
    }
    double totalVariance = sumYSquared / n - (meanY * meanY);
    if (totalVariance <= 0) {
        rSquared = 0; // 避免除以零
    } else {
        rSquared = 1 - (sumResidualsSquared / totalVariance);
    }
    cubeRoot = std::pow(10, -1.0 / k);
    cubeRoot = (cubeRoot-1)*100;
}

// log取值
QVector<double> DataAnalysisWindow::logvalue(QVector<double> valuelog)
{
    QVector<double> logv;
    for (double value : valuelog) {
        if (value > 0) { // 确保不会对0或负数取对数
            logv.push_back(std::log10(value)); // 使用以10为底的对数
        } else {
            // 处理0或负数的情况，例如跳过或设置一个默认值
            logv.append(0);
        }
    }
    return logv;
}

// 指导建议表格
void DataAnalysisWindow::guide()
{
    if(MainWindow::isBzsy){
        QStringList rowInfoList;
        rowInfoList<<" "<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT值"<<"样本浓度\nng/ul"<<"总浓度\nng/ul"<<"男性浓度\nng/ul"<<"女性浓度\nng/ul"
                  <<"男女浓度比例"<<"降解指数DI"<<"抑制指数ICS"<<"检测方案"<<"稀释方案\n样本体积\nul"<<"稀释方案\n稀释液体积\nul"<<"扩增上样体积\nul"<<"备注";
        ui->tableWidget->setColumnCount(rowInfoList.length());
        ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
        ui->tableWidget->resizeColumnsToContents(); // 根据内容调整列宽
        ui->tableWidget->setColumnHidden(0, true);
        //总浓度值
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            if(i%4==0){
                ui->tableWidget->setItem(i,7, new QTableWidgetItem(ui->tableWidget->item(i+2,6)->text()));
            }else if(i%4==1){
                ui->tableWidget->setItem(i,7,new QTableWidgetItem(ui->tableWidget->item(i+1,6)->text()));
            }else if(i%4==2){
                ui->tableWidget->setItem(i,7,new QTableWidgetItem(ui->tableWidget->item(i,6)->text()));
            }else if(i%4==3){
                ui->tableWidget->setItem(i,7,new QTableWidgetItem(ui->tableWidget->item(i-1,6)->text()));
            }
        }
        //标准品CQ浓度平均值
        double valCJ=0;
        int ctNum=0;
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if(ui->tableWidget->item(i+1,3)->text()=="标准品"){
                valCJ+=ui->tableWidget->item(i+3,5)->text().toDouble();
                ctNum++;
            }
        }
        valCJ=valCJ/ctNum;
        //样本名相同处理
        QStringList ybmsame;
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if(!ybmsame.contains(ui->tableWidget->item(i,2)->text())){
                ybmsame.append(ui->tableWidget->item(i,2)->text());
            }
        }
        QList<int> ybmnum;
        QList<double> AL,AS,Y,CQ;
        for(int i=0;i<ybmsame.length();i++){
            ybmnum.append(0);
            AL.append(0);
            AS.append(0);
            Y.append(0);
            CQ.append(0);
        }
        for (int i=0;i<ui->tableWidget->rowCount();i+=4) {
            QString cell_value = ui->tableWidget->item(i+1,2)->text();
            for(int j = 0;j<ybmsame.length();j++){
                if(cell_value==ybmsame[j]){
                    double cell_valueAL = QString::number(ui->tableWidget->item(i+1,6)->text().toDouble(),'f',4).toDouble();
                    double cell_valueAS = QString::number(ui->tableWidget->item(i+2,6)->text().toDouble(),'f',4).toDouble();
                    double cell_valueY = QString::number(ui->tableWidget->item(i,6)->text().toDouble(),'f',4).toDouble();
                    double cell_valueCQ = QString::number(ui->tableWidget->item(i+3,5)->text().toDouble(),'f',4).toDouble();
                    double cell_valueCQF = QString::number(ui->tableWidget->item(i,5)->text().toDouble(),'f',4).toDouble();
                    double cell_valueCQV = QString::number(ui->tableWidget->item(i+2,5)->text().toDouble(),'f',4).toDouble();
                    double cell_valueCQR = QString::number(ui->tableWidget->item(i+1,5)->text().toDouble(),'f',4).toDouble();
                    AL[j]+=cell_valueAL;
                    AS[j]+=cell_valueAS;
                    Y[j]+=cell_valueY;
                    CQ[j]+=cell_valueCQ;
                    ybmnum[j]++;
                    if(CQvalreC.contains(ybmsame[j])){
                        QList<double> val;
                        val = CQvalreC.value(ybmsame[j]);
                        val.append(cell_valueCQ);
                        CQvalreC[ybmsame[j]] = val;
                    }else{
                        QList<double> val;
                        val.append(cell_valueCQ);
                        CQvalreC.insert(ybmsame[j],val);
                    }
                    if(CQvalreF.contains(ybmsame[j])){
                        QList<double> val;
                        val = CQvalreF.value(ybmsame[j]);
                        val.append(cell_valueCQF);
                        CQvalreF[ybmsame[j]] = val;
                    }else{
                        QList<double> val;
                        val.append(cell_valueCQF);
                        CQvalreF.insert(ybmsame[j],val);
                    }
                    if(CQvalreV.contains(ybmsame[j])){
                        QList<double> val;
                        val = CQvalreV.value(ybmsame[j]);
                        val.append(cell_valueCQV);
                        CQvalreV[ybmsame[j]] = val;
                    }else{
                        QList<double> val;
                        val.append(cell_valueCQV);
                        CQvalreV.insert(ybmsame[j],val);
                    }
                    if(CQvalreR.contains(ybmsame[j])){
                        QList<double> val;
                        val = CQvalreR.value(ybmsame[j]);
                        val.append(cell_valueCQR);
                        CQvalreR[ybmsame[j]] = val;
                    }else{
                        QList<double> val;
                        val.append(cell_valueCQR);
                        CQvalreR.insert(ybmsame[j],val);
                    }
                }
            }
        }
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            double valnVIC,valnROX,valnFAM,valnCY5C;
            for(int k = 0;k<ybmsame.length();k++){
                if(ui->tableWidget->item(i+1,2)->text()==ybmsame[k]){
                    valnVIC=AS[k]/ybmnum[k];
                    valnROX=AL[k]/ybmnum[k];
                    valnFAM=Y[k]/ybmnum[k];
                    valnCY5C=CQ[k]/ybmnum[k];
                }
            }
            //男女浓度比例
            QStringList mwval=mwnd(valnVIC,valnFAM);
            for(int j=0;j<3;j++){
                ui->tableWidget->setItem(i,8+j,new QTableWidgetItem(QString::number(mwval[j].toDouble(),'f',2)));
            }
            // 抑制指数降解指数
            QStringList zsjsv=zsjs(valnVIC,valnROX,valnCY5C,valCJ);
            for(int j=0;j<2;j++){
                ui->tableWidget->setItem(i,11+j,new QTableWidgetItem(zsjsv[j]));
            }
            // 建议方案
            QStringList guid = gui(valnROX,valnVIC,valnFAM,valnCY5C,valCJ);
            if(guid.length()==4){
                for(int j=0;j<4;j++){
                    ui->tableWidget->setItem(i,13+j,new QTableWidgetItem(guid[j]));
                }
            }else if(guid.length()==5){
                for(int j=0;j<5;j++){
                    ui->tableWidget->setItem(i,13+j,new QTableWidgetItem(guid[j]));
                }
            }
        }
        numlu();
        if(true){
            QMap<QString, QList<double>>::const_iterator it;
            for (it = CQvalreF.constBegin(); it != CQvalreF.constEnd(); ++it) {
                const QString& key = it.key();
                const QList<double>& value = it.value();
                double mean = Mean(value);
                double std = STD(value);
                CQMeanF.insert(key,mean);
                CQSTDF.insert(key,std);
            }
        }
        if(true){
            QMap<QString, QList<double>>::const_iterator it;
            for (it = CQvalreV.constBegin(); it != CQvalreV.constEnd(); ++it) {
                const QString& key = it.key();
                const QList<double>& value = it.value();
                double mean = Mean(value);
                double std = STD(value);
                CQMeanV.insert(key,mean);
                CQSTDV.insert(key,std);
            }
        }
        if(true){
            QMap<QString, QList<double>>::const_iterator it;
            for (it = CQvalreR.constBegin(); it != CQvalreR.constEnd(); ++it) {
                const QString& key = it.key();
                const QList<double>& value = it.value();
                double mean = Mean(value);
                double std = STD(value);
                CQMeanR.insert(key,mean);
                CQSTDR.insert(key,std);
            }
        }
        if(true){
            QMap<QString, QList<double>>::const_iterator it;
            for (it = CQvalreC.constBegin(); it != CQvalreC.constEnd(); ++it) {
                const QString& key = it.key();
                const QList<double>& value = it.value();
                double mean = Mean(value);
                double std = STD(value);
                CQMeanC.insert(key,mean);
                CQSTDC.insert(key,std);
            }
        }
    }else{
        QStringList rowInfoList;
        rowInfoList<<" "<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT值"<<"样本浓度\nng/ul"<<"总浓度\nng/ul"<<"男性浓度\nng/ul"<<"女性浓度\nng/ul"
                  <<"男女浓度比例"<<"降解指数DI"<<"抑制指数ICS"<<"检测方案"<<"稀释方案\n样本体积\nul"<<"稀释方案\n稀释液体积\nul"<<"扩增上样体积\nul"<<"备注";
        ui->tableWidget->setColumnCount(rowInfoList.length());
        ui->tableWidget->setHorizontalHeaderLabels(rowInfoList);
        ui->tableWidget->resizeColumnsToContents(); // 根据内容调整列宽
        ui->tableWidget->setColumnHidden(0, true);
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            for(int j=6;j<18;j++){
                ui->tableWidget->setItem(i,j,new QTableWidgetItem(" "));
            }
        }
    }

}

// 男性浓度，女性浓度，男女浓度比例计算
QStringList DataAnalysisWindow::mwnd(double valnVIC,double valnFAM)
{
    QStringList mwval;
    if(valnVIC==0&&valnFAM==0){
        mwval.append("un");
        mwval.append("un");
        mwval.append("-");
    }else if(valnVIC!=0&&valnFAM==0){
        mwval.append("un");
        if(valnVIC<0.003){
            mwval.append("un");
        }else{
            mwval.append(QString::number(valnVIC,'f',4));
        }
        mwval.append("-");
    }else if(valnVIC==0&&valnFAM!=0){
        mwval.append("un");
        mwval.append("un");
        mwval.append("-");
    }else if(valnVIC!=0&&valnFAM!=0){
        if(valnVIC/valnFAM<2){
            mwval.append(QString::number(valnVIC,'f',4));
            mwval.append("un");
            mwval.append("-");
        }else if(valnVIC/valnFAM>=2&&valnVIC>=0.003&&valnVIC<0.02&&valnFAM>0.001){
            mwval.append(QString::number(valnVIC,'f',4));
            mwval.append("un");
            mwval.append("-");
        }else if(valnVIC/valnFAM>=2&&valnVIC>=0.02&&valnFAM>0.001){
            mwval.append(QString::number(valnFAM*1.39,'f',4));
            mwval.append(QString::number(valnVIC-1.39*valnFAM,'f',4));
            mwval.append("1:"+QString::number(valnVIC-1.39*valnFAM/(valnFAM*1.39),'f',2));
        }else{
            mwval.append("-");
            mwval.append("-");
            mwval.append("-");
        }
    }else{
        mwval.append("-");
        mwval.append("-");
        mwval.append("-");
    }
    return mwval;
}

// 抑制指数，降解指数计算
QStringList DataAnalysisWindow::zsjs(double valnVIC, double valnROX, double valnCY5C, double valCJ)
{
    qDebug()<<valnVIC<<valnROX<<valnCY5C<<valCJ;
    QStringList zs;
    if(valnVIC==0||valnROX==0){
        zs.append("-");
    }else if(valnVIC!=0&&valnROX!=0){
        zs.append(QString::number(valnVIC/valnROX,'f',2));
    }
    zs.append(QString::number(valnCY5C-valCJ,'f',2));
    return zs;
}

// 指导建议及稀释/扩增方案计算
QStringList DataAnalysisWindow::gui(double valnROX,double valnVIC,double valnFAM,double valnCY5C,double valCJ)
{
    QStringList row_data;
    QString path=QCoreApplication::applicationDirPath(); //获取当前项目路径
    QFile file(":/xml/config.xml");//获取文件完整路径
    if(!file.open(QFile::ReadOnly)){//判断文件是否存在
        QMessageBox msgBox;
        msgBox.setText("config.xml文件缺失！");
        msgBox.exec();
    }
    QDomDocument doc;
    QStringList Q;
    QStringList Q41,Q42,Q43,Q44,Q45,Q46,Q47,Q48,Q49,Q50,Q51,Q52,Q53,Q54,Q55,Q56,Q57,Q58,Q59,Q60,Q61,Q62,Q63,Q64,Q65,Q66,Q67,Q68,Q69,Q70,Q71,Q72,Q73,Q74,Q75,Q76,Q77,Q78,Q79,Q80,Q81,Q82,Q83,Q84,Q85,Q86,Q87,Q88,Q89,Q90,Q91,Q92,Q93,Q94,Q95,Q96,Q97,Q98,Q99,Q100,Q101,Q102,Q103,Q104;
    QStringList QQ;
    //设置config.xml到文档
    if(!doc.setContent(&file))
    {
        file.close();
        return {};
    }
    file.close();
    //返回根节点
    QDomElement root=doc.documentElement();
    //获得第一个子节点
    QDomNode node=root.firstChild();
    while(!node.isNull())  //如果节点不空
    {
        if(node.isElement()) //如果节点是元素
        {
            //转换为元素
            QDomElement e=node.toElement();
            QString ICS = e.attribute("ICS");
            QString DI = e.attribute("DI");
            QString ASY = e.attribute("ASY");
            QString DI1 = e.attribute("DI1");
            QString DIN1 = e.attribute("DIN1");
            QString DIN2 = e.attribute("DIN2");
            QString DIN3 = e.attribute("DIN3");
            QString DIN4 = e.attribute("DIN4");
            QString DIN5 = e.attribute("DIN5");
            QString DIN6 = e.attribute("DIN6");
            QString DIN7 = e.attribute("DIN7");
            if (e.tagName()=="value"){
                Q.append(ICS);
                Q.append(DI);
                Q.append(ASY);
                Q.append(DI1);
                Q.append(DIN1);
                Q.append(DIN2);
                Q.append(DIN3);
                Q.append(DIN4);
                Q.append(DIN5);
                Q.append(DIN6);
                Q.append(DIN7);
            }
            QString info1 = e.attribute("info1");
            QString info2 = e.attribute("info2");
            QString info3 = e.attribute("info3");
            QString info4 = e.attribute("info4");
            if (e.tagName()=="k41") {
                Q41.append(info1);
                Q41.append(info2);
                Q41.append(info3);
                Q41.append(info4);
            }else if (e.tagName()=="k42") {
                Q42.append(info1);
                Q42.append(info2);
                Q42.append(info3);
                Q42.append(info4);
            }else if (e.tagName()=="k43") {
                Q43.append(info1);
                Q43.append(info2);
                Q43.append(info3);
                Q43.append(info4);
            }else if (e.tagName()=="k44") {
                Q44.append(info1);
                Q44.append(info2);
                Q44.append(info3);
                Q44.append(info4);
            }else if (e.tagName()=="k45") {
                Q45.append(info1);
                Q45.append(info2);
                Q45.append(info3);
                Q45.append(info4);
            }else if (e.tagName()=="k46") {
                Q46.append(info1);
                Q46.append(info2);
                Q46.append(info3);
                Q46.append(info4);
            }else if (e.tagName()=="k47") {
                Q47.append(info1);
                Q47.append(info2);
                Q47.append(info3);
                Q47.append(info4);
            }else if (e.tagName()=="k48") {
                Q48.append(info1);
                Q48.append(info2);
                Q48.append(info3);
                Q48.append(info4);
            }else if (e.tagName()=="k49") {
                Q49.append(info1);
                Q49.append(info2);
                Q49.append(info3);
                Q49.append(info4);
            }else if (e.tagName()=="k50") {
                Q50.append(info1);
                Q50.append(info2);
                Q50.append(info3);
                Q50.append(info4);
            }else if (e.tagName()=="k51") {
                Q51.append(info1);
                Q51.append(info2);
                Q51.append(info3);
                Q51.append(info4);
            }else if (e.tagName()=="k52") {
                Q52.append(info1);
                Q52.append(info2);
                Q52.append(info3);
                Q52.append(info4);
            }else if (e.tagName()=="k53") {
                Q53.append(info1);
                Q53.append(info2);
                Q53.append(info3);
                Q53.append(info4);
            }else if (e.tagName()=="k54") {
                Q54.append(info1);
                Q54.append(info2);
                Q54.append(info3);
                Q54.append(info4);
            }else if (e.tagName()=="k55") {
                Q55.append(info1);
                Q55.append(info2);
                Q55.append(info3);
                Q55.append(info4);
            }else if (e.tagName()=="k56") {
                Q56.append(info1);
                Q56.append(info2);
                Q56.append(info3);
                Q56.append(info4);
            }else if (e.tagName()=="k57") {
                Q57.append(info1);
                Q57.append(info2);
                Q57.append(info3);
                Q57.append(info4);
            }else if (e.tagName()=="k58") {
                Q58.append(info1);
                Q58.append(info2);
                Q58.append(info3);
                Q58.append(info4);
            }else if (e.tagName()=="k59") {
                Q59.append(info1);
                Q59.append(info2);
                Q59.append(info3);
                Q59.append(info4);
            }else if (e.tagName()=="k60") {
                Q60.append(info1);
                Q60.append(info2);
                Q60.append(info3);
                Q60.append(info4);
            }else if (e.tagName()=="k61") {
                Q61.append(info1);
                Q61.append(info2);
                Q61.append(info3);
                Q61.append(info4);
            }else if (e.tagName()=="k62") {
                Q62.append(info1);
                Q62.append(info2);
                Q62.append(info3);
                Q62.append(info4);
            }else if (e.tagName()=="k63") {
                Q63.append(info1);
                Q63.append(info2);
                Q63.append(info3);
                Q63.append(info4);
            }else if (e.tagName()=="k64") {
                Q64.append(info1);
                Q64.append(info2);
                Q64.append(info3);
                Q64.append(info4);
            }else if (e.tagName()=="k65") {
                Q65.append(info1);
                Q65.append(info2);
                Q65.append(info3);
                Q65.append(info4);
            }else if (e.tagName()=="k66") {
                Q66.append(info1);
                Q66.append(info2);
                Q66.append(info3);
                Q66.append(info4);
            }else if (e.tagName()=="k67") {
                Q67.append(info1);
                Q67.append(info2);
                Q67.append(info3);
                Q67.append(info4);
            }else if (e.tagName()=="k68") {
                Q68.append(info1);
                Q68.append(info2);
                Q68.append(info3);
                Q68.append(info4);
            }else if (e.tagName()=="k69") {
                Q69.append(info1);
                Q69.append(info2);
                Q69.append(info3);
                Q69.append(info4);
            }else if (e.tagName()=="k70") {
                Q70.append(info1);
                Q70.append(info2);
                Q70.append(info3);
                Q70.append(info4);
            }else if (e.tagName()=="k71") {
                Q71.append(info1);
                Q71.append(info2);
                Q71.append(info3);
                Q71.append(info4);
            }else if (e.tagName()=="k72") {
                Q72.append(info1);
                Q72.append(info2);
                Q72.append(info3);
                Q72.append(info4);
            }else if (e.tagName()=="k73") {
                Q73.append(info1);
                Q73.append(info2);
                Q73.append(info3);
                Q73.append(info4);
            }else if (e.tagName()=="k74") {
                Q74.append(info1);
                Q74.append(info2);
                Q74.append(info3);
                Q74.append(info4);
            }else if (e.tagName()=="k75") {
                Q75.append(info1);
                Q75.append(info2);
                Q75.append(info3);
                Q75.append(info4);
            }else if (e.tagName()=="k76") {
                Q76.append(info1);
                Q76.append(info2);
                Q76.append(info3);
                Q76.append(info4);
            }else if (e.tagName()=="k77") {
                Q77.append(info1);
                Q77.append(info2);
                Q77.append(info3);
                Q77.append(info4);
            }else if (e.tagName()=="k78") {
                Q78.append(info1);
                Q78.append(info2);
                Q78.append(info3);
                Q78.append(info4);
            }else if (e.tagName()=="k79") {
                Q79.append(info1);
                Q79.append(info2);
                Q79.append(info3);
                Q79.append(info4);
            }else if (e.tagName()=="k80") {
                Q80.append(info1);
                Q80.append(info2);
                Q80.append(info3);
                Q80.append(info4);
            }else if (e.tagName()=="k81") {
                Q81.append(info1);
                Q81.append(info2);
                Q81.append(info3);
                Q81.append(info4);
            }else if (e.tagName()=="k82") {
                Q82.append(info1);
                Q82.append(info2);
                Q82.append(info3);
                Q82.append(info4);
            }else if (e.tagName()=="k83") {
                Q83.append(info1);
                Q83.append(info2);
                Q83.append(info3);
                Q83.append(info4);
            }else if (e.tagName()=="k84") {
                Q84.append(info1);
                Q84.append(info2);
                Q84.append(info3);
                Q84.append(info4);
            }else if (e.tagName()=="k85") {
                Q85.append(info1);
                Q85.append(info2);
                Q85.append(info3);
                Q85.append(info4);
            }else if (e.tagName()=="k86") {
                Q86.append(info1);
                Q86.append(info2);
                Q86.append(info3);
                Q86.append(info4);
            }else if (e.tagName()=="k87") {
                Q87.append(info1);
                Q87.append(info2);
                Q87.append(info3);
                Q87.append(info4);
            }else if (e.tagName()=="k88") {
                Q88.append(info1);
                Q88.append(info2);
                Q88.append(info3);
                Q88.append(info4);
            }else if (e.tagName()=="k89") {
                Q89.append(info1);
                Q89.append(info2);
                Q89.append(info3);
                Q89.append(info4);
            }else if (e.tagName()=="k90") {
                Q90.append(info1);
                Q90.append(info2);
                Q90.append(info3);
                Q90.append(info4);
            }else if (e.tagName()=="k91") {
                Q91.append(info1);
                Q91.append(info2);
                Q91.append(info3);
                Q91.append(info4);
            }else if (e.tagName()=="k92") {
                Q92.append(info1);
                Q92.append(info2);
                Q92.append(info3);
                Q92.append(info4);
            }else if (e.tagName()=="k93") {
                Q93.append(info1);
                Q93.append(info2);
                Q93.append(info3);
                Q93.append(info4);
            }else if (e.tagName()=="k94") {
                Q94.append(info1);
                Q94.append(info2);
                Q94.append(info3);
                Q94.append(info4);
            }else if (e.tagName()=="k95") {
                Q95.append(info1);
                Q95.append(info2);
                Q95.append(info3);
                Q95.append(info4);
            }else if (e.tagName()=="k96") {
                Q96.append(info1);
                Q96.append(info2);
                Q96.append(info3);
                Q96.append(info4);
            }else if (e.tagName()=="k97") {
                Q97.append(info1);
                Q97.append(info2);
                Q97.append(info3);
                Q97.append(info4);
            }else if (e.tagName()=="k98") {
                Q98.append(info1);
                Q98.append(info2);
                Q98.append(info3);
                Q98.append(info4);
            }else if (e.tagName()=="k99") {
                Q99.append(info1);
                Q99.append(info2);
                Q99.append(info3);
                Q99.append(info4);
            }else if (e.tagName()=="k100") {
                Q100.append(info1);
                Q100.append(info2);
                Q100.append(info3);
                Q100.append(info4);
            }else if (e.tagName()=="k101") {
                Q101.append(info1);
                Q101.append(info2);
                Q101.append(info3);
                Q101.append(info4);
            }else if (e.tagName()=="k102") {
                Q102.append(info1);
                Q102.append(info2);
                Q102.append(info3);
                Q102.append(info4);
            }else if (e.tagName()=="k103") {
                Q103.append(info1);
                Q103.append(info2);
                Q103.append(info3);
                Q103.append(info4);
            }else if (e.tagName()=="k104") {
                Q104.append(info1);
                Q104.append(info2);
                Q104.append(info3);
                Q104.append(info4);
            }

            QDomNodeList list=e.childNodes();
            for(int i=0;i<list.count();i++)
            {
                QDomNode n=list.at(i);
                if(node.isElement())
                    QQ.append(n.toElement().text());
            }
        }
        //下一个兄弟节点
        node=node.nextSibling();
    }
    QString ICSS1 = Q[0];
    double ICS1 = ICSS1.toDouble();
    QString DII1 = Q[1];
    double DI1 = DII1.toDouble();
    QString ASYY1 = Q[2];
    double ASY1 = ASYY1.toDouble();
    QString DII2 = Q[3];
    double DI2 = DII2.toDouble();

    QString DINN1 = Q[4];
    double DIN1 = DINN1.toDouble();
    QString DINN2 = Q[5];
    double DIN2 = DINN2.toDouble();
    QString DINN3 = Q[6];
    double DIN3 = DINN3.toDouble();
    QString DINN4 = Q[7];
    double DIN4 = DINN4.toDouble();
    QString DINN5 = Q[8];
    double DIN5 = DINN5.toDouble();
    QString DINN6 = Q[9];
    double DIN6 = DINN6.toDouble();
    QString DINN7 = Q[10];
    double DIN7 = DINN7.toDouble();

    QString ALL1 = QQ[0];
    double AL1 = ALL1.toDouble();
    QString YY1 = QQ[1];
    double Y1 = YY1.toDouble();
    QString YY2 = QQ[2];
    double Y2 = YY2.toDouble();
    QString ASS1 = QQ[3];
    double AS1 = ASS1.toDouble();
    QString ASS2 = QQ[4];
    double AS2 = ASS2.toDouble();
    QString ASS3 = QQ[5];
    double AS3 = ASS3.toDouble();
    QString ASS4 = QQ[6];
    double AS4 = ASS4.toDouble();
    QString ALL2 = QQ[7];
    double AL2 = ALL2.toDouble();
    QString ALL3 = QQ[8];
    double AL3 = ALL3.toDouble();
    QString ALL4 = QQ[9];
    double AL4 = ALL4.toDouble();
    QString ALL5 = QQ[10];
    double AL5 = ALL5.toDouble();
    QString ASS5 = QQ[11];
    double AS5 = ASS5.toDouble();
    QString ASS6 = QQ[12];
    double AS6 = ASS6.toDouble();
    QString ASS7 = QQ[13];
    double AS7 = ASS7.toDouble();
    QString ASS8 = QQ[14];
    double AS8 = ASS8.toDouble();
    QString ASS9 = QQ[15];
    double AS9 = ASS9.toDouble();
    QString YY3 = QQ[16];
    double Y3 = YY3.toDouble();
    QString YY4 = QQ[17];
    double Y4 = YY4.toDouble();
    QString YY5 = QQ[18];
    double Y5 = YY5.toDouble();
    QString YY6 = QQ[19];
    double Y6 = YY6.toDouble();
    QString ALL6 = QQ[20];
    double AL6 = ALL6.toDouble();

    QString ALNN1 = QQ[21];
    double ALN1 = ALNN1.toDouble();
    QString ALNN2 = QQ[22];
    double ALN2 = ALNN2.toDouble();
    QString ALNN3 = QQ[23];
    double ALN3 = ALNN3.toDouble();
    QString ALNN4 = QQ[24];
    double ALN4 = ALNN4.toDouble();
    QString ALNN5 = QQ[25];
    double ALN5 = ALNN5.toDouble();
    QString ALNN6 = QQ[26];
    double ALN6 = ALNN6.toDouble();

    QString ALNN7 = QQ[27];
    double ALN7 = ALNN7.toDouble();
    QString ALNN8 = QQ[28];
    double ALN8 = ALNN8.toDouble();
    QString ALNN9 = QQ[29];
    double ALN9 = ALNN9.toDouble();
    QString ALNN10 = QQ[30];
    double ALN10 = ALNN10.toDouble();
    QString ALNN11 = QQ[31];
    double ALN11 = ALNN11.toDouble();
    QString ALNN12 = QQ[32];
    double ALN12 = ALNN12.toDouble();

    QString ALNN13 = QQ[33];
    double ALN13 = ALNN13.toDouble();
    QString ALNN14 = QQ[34];
    double ALN14 = ALNN14.toDouble();
    QString ALNN15 = QQ[35];
    double ALN15 = ALNN15.toDouble();
    QString ALNN16 = QQ[36];
    double ALN16 = ALNN16.toDouble();
    QString ALNN17 = QQ[37];
    double ALN17 = ALNN17.toDouble();
    QString ALNN18 = QQ[38];
    double ALN18 = ALNN18.toDouble();

    QString ALNN19 = QQ[39];
    double ALN19 = ALNN19.toDouble();
    QString ALNN20 = QQ[40];
    double ALN20 = ALNN20.toDouble();
    QString ALNN21 = QQ[41];
    double ALN21 = ALNN21.toDouble();
    QString ALNN22 = QQ[42];
    double ALN22 = ALNN22.toDouble();
    QString ALNN23 = QQ[43];
    double ALN23 = ALNN23.toDouble();
    QString ALNN24 = QQ[44];
    double ALN24 = ALNN24.toDouble();

    QString ASNN1 = QQ[45];
    double ASN1 = ASNN1.toDouble();
    QString ASNN2 = QQ[46];
    double ASN2 = ASNN2.toDouble();
    QString ASNN3 = QQ[47];
    double ASN3 = ASNN3.toDouble();
    QString ASNN4 = QQ[48];
    double ASN4 = ASNN4.toDouble();
    QString ASNN5 = QQ[49];
    double ASN5 = ASNN5.toDouble();
    QString ASNN6 = QQ[50];
    double ASN6 = ASNN6.toDouble();
    QString ASNN7 = QQ[51];
    double ASN7 = ASNN7.toDouble();

    QString ASNN8 = QQ[52];
    double ASN8 = ASNN8.toDouble();
    QString ASNN9 = QQ[53];
    double ASN9 = ASNN9.toDouble();
    QString ASNN10 = QQ[54];
    double ASN10 = ASNN10.toDouble();
    QString ASNN11 = QQ[55];
    double ASN11 = ASNN11.toDouble();
    QString ASNN12 = QQ[56];
    double ASN12 = ASNN12.toDouble();

    QString ALNN25 = QQ[57];
    double ALN25 = ALNN25.toDouble();
    QString ALNN26 = QQ[58];
    double ALN26 = ALNN26.toDouble();
    QString ALNN27 = QQ[59];
    double ALN27 = ALNN27.toDouble();
    QString ALNN28 = QQ[60];
    double ALN28 = ALNN28.toDouble();
    QString ALNN29 = QQ[61];
    double ALN29 = ALNN29.toDouble();
    QString ALNN30 = QQ[62];
    double ALN30 = ALNN30.toDouble();

    QString YNN1 = QQ[63];
    double YN1 = YNN1.toDouble();
    QString YNN2 = QQ[64];
    double YN2 = YNN2.toDouble();
    QString YNN3 = QQ[65];
    double YN3 = YNN3.toDouble();
    QString YNN4 = QQ[66];
    double YN4 = YNN4.toDouble();
    QString YNN5 = QQ[67];
    double YN5 = YNN5.toDouble();

    if(valnROX!=0&&valnVIC!=0){
        int xY = qRound(5*(valnFAM/0.5)-5);
        QString XY = QString::number(xY);
        int xY2 = qRound(5*(valnFAM/0.8)-5);
        QString XY2 = QString::number(xY2);
        int xAS1 = qRound(5*(valnVIC/0.5)-5);
        QString XAS1 = QString::number(xAS1);
        int xAS2 = qRound(5*(valnVIC/0.4)-5);
        QString XAS2 = QString::number(xAS2);
        int xAL1 = qRound(5*(valnROX/0.16)-5);
        QString XAL1 = QString::number(xAL1);
        int xAL2 = qRound(5*(valnROX/0.1)-5);
        QString XAL2 = QString::number(xAL2);
        int xAL3 = qRound(5*(valnROX/0.06)-5);
        QString XAL3 = QString::number(xAL3);
        int xAL4 = qRound(5*(valnROX/0.05)-5);
        QString XAL4 = QString::number(xAL4);
        int xAL5 = qRound(5*(valnROX/0.02)-5);
        QString XAL5 = QString::number(xAL5);

        if(valnVIC/valnROX<DIN1&&valnVIC/valnFAM>ASY1&&valnVIC>AS3&&valnFAM>Y3){
            if(valnFAM>Y3&&valnFAM<Y4){
                row_data<<Q41[1]<<Q41[2]<<Q41[3]<<Q41[0]<<"可能为男女混合样";
            }else if(valnFAM>Y4&&valnFAM<Y5){
                row_data<<Q42[1]<<Q42[2]<<Q42[3]<<Q42[0]<<"可能为男女混合样";
            }else if(valnFAM>Y5&&valnFAM<Y6){
                row_data<<Q43[1]<<Q43[2]<<Q43[3]<<Q43[0]<<"可能为男女混合样";
            }else if(valnFAM>Y6){
                row_data<<Q44[1]<<Q44[2]<<XY+"ul"<<Q44[0]<<"可能为男女混合样";
            }
        }else if(valnVIC/valnROX>DIN1&&valnVIC/valnROX<DIN7&&valnVIC/valnFAM>=ASY1&&valnFAM>=YN1){
            if(valnFAM>=YN1&&valnFAM<YN2){
                row_data<<Q100[1]<<Q100[2]<<Q100[3]<<Q100[0]<<"可能为男女混合样";
            }else if(valnFAM>=YN2&&valnFAM<YN3){
                row_data<<Q101[1]<<Q101[2]<<Q101[3]<<Q101[0]<<"可能为男女混合样";
            }else if(valnFAM>=YN3&&valnFAM<YN4){
                row_data<<Q102[1]<<Q102[2]<<Q102[3]<<Q102[0]<<"可能为男女混合样";
            }else if(valnFAM>=YN4&&valnFAM<YN5){
                row_data<<Q103[1]<<Q103[2]<<Q103[3]<<Q103[0]<<"可能为男女混合样";
            }else if(valnFAM>=YN5){
                row_data<<Q104[1]<<Q104[2]<<XY2+"ul"<<Q104[0]<<"可能为男女混合样";
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX<DIN1){
            if(valnVIC<ASN1){
                row_data<<Q46[1]<<Q46[2]<<Q46[3]<<Q46[0];
            }else if(valnVIC>=ASN1&&valnVIC<=ASN2){
                row_data<<Q47[1]<<Q47[2]<<Q47[3]<<Q47[0];
            }else if(valnVIC>ASN2&&valnVIC<=ASN3){
                row_data<<Q48[1]<<Q48[2]<<Q48[3]<<Q48[0];
            }else if(valnVIC>ASN3&&valnVIC<=ASN4){
                row_data<<Q49[1]<<Q49[2]<<Q49[3]<<Q49[0];
            }else if(valnVIC>ASN4&&valnVIC<=ASN5){
                row_data<<Q50[1]<<Q50[2]<<Q50[3]<<Q50[0];
            }else if(valnVIC>ASN5&&valnVIC<=ASN6){
                row_data<<Q51[1]<<Q51[2]<<Q51[3]<<Q51[0];
            }else if(valnVIC>ASN6){
                row_data<<Q52[1]<<Q52[2]<<XAS2+"ul"<<Q52[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX>=DIN1&&valnVIC/valnROX<=DIN2){
            if(valnROX<ALN1&&valnVIC<ASN7){
                row_data<<Q53[1]<<Q53[2]<<Q53[3]<<Q53[0];
            }else if(valnROX<ALN1&&valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }else if(valnROX>=ALN1&&valnROX<=ALN2){
                row_data<<Q55[1]<<Q55[2]<<Q55[3]<<Q55[0];
            }else if(valnROX>ALN2&&valnROX<=ALN3){
                row_data<<Q56[1]<<Q56[2]<<Q56[3]<<Q56[0];
            }else if(valnROX>ALN3&&valnROX<=ALN4){
                row_data<<Q57[1]<<Q57[2]<<Q57[3]<<Q57[0];
            }else if(valnROX>ALN4&&valnROX<=ALN5){
                row_data<<Q58[1]<<Q58[2]<<Q58[3]<<Q58[0];
            }else if(valnROX>ALN5&&valnROX<=ALN6){
                row_data<<Q59[1]<<Q59[2]<<Q59[3]<<Q59[0];
            }else if(valnROX>ALN6){
                row_data<<Q60[1]<<Q60[2]<<XAL1+"ul"<<Q60[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX>DIN2&&valnVIC/valnROX<=DIN3){
            if(valnROX<ALN7&&valnVIC<ASN7){
                row_data<<Q61[1]<<Q61[2]<<Q61[3]<<Q61[0];
            }else if(valnROX<ALN7&&valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }else if(valnROX>=ALN7&&valnROX<=ALN8){
                row_data<<Q63[1]<<Q63[2]<<Q63[3]<<Q63[0];
            }else if(valnROX>ALN8&&valnROX<=ALN9){
                row_data<<Q64[1]<<Q64[2]<<Q64[3]<<Q64[0];
            }else if(valnROX>ALN9&&valnROX<=ALN10){
                row_data<<Q65[1]<<Q65[2]<<Q65[3]<<Q65[0];
            }else if(valnROX>ALN10&&valnROX<=ALN11){
                row_data<<Q66[1]<<Q66[2]<<Q66[3]<<Q66[0];
            }else if(valnROX>ALN11&&valnROX<=ALN12){
                row_data<<Q67[1]<<Q67[2]<<Q67[3]<<Q67[0];
            }else if(valnROX>ALN12){
                row_data<<Q68[1]<<Q68[2]<<XAL2+"ul"<<Q68[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX>DIN3&&valnVIC/valnROX<=DIN4){
            if(valnROX<ALN13&&valnVIC<ASN7){
                row_data<<Q69[1]<<Q69[2]<<Q69[3]<<Q69[0];
            }else if(valnROX<ALN13&&valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }else if(valnROX>=ALN13&&valnROX<=ALN14){
                row_data<<Q71[1]<<Q71[2]<<Q71[3]<<Q71[0];
            }else if(valnROX>ALN14&&valnROX<=ALN15){
                row_data<<Q72[1]<<Q72[2]<<Q72[3]<<Q72[0];
            }else if(valnROX>ALN15&&valnROX<=ALN16){
                row_data<<Q73[1]<<Q73[2]<<Q73[3]<<Q73[0];
            }else if(valnROX>ALN16&&valnROX<=ALN17){
                row_data<<Q74[1]<<Q74[2]<<Q74[3]<<Q74[0];
            }else if(valnROX>ALN17&&valnROX<=ALN18){
                row_data<<Q75[1]<<Q75[2]<<Q75[3]<<Q75[0];
            }else if(valnROX>ALN18){
                row_data<<Q76[1]<<Q76[2]<<XAL3+"ul"<<Q76[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX>DIN4&&valnVIC/valnROX<=DIN5){
            if(valnROX<ALN19&&valnVIC<ASN7){
                row_data<<Q77[1]<<Q77[2]<<Q77[3]<<Q77[0];
            }else if(valnROX<ALN19&&valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }else if(valnROX>=ALN19&&valnROX<=ALN20){
                row_data<<Q79[1]<<Q79[2]<<Q79[3]<<Q79[0];
            }else if(valnROX>ALN20&&valnROX<=ALN21){
                row_data<<Q80[1]<<Q80[2]<<Q80[3]<<Q80[0];
            }else if(valnROX>ALN21&&valnROX<=ALN22){
                row_data<<Q81[1]<<Q81[2]<<Q81[3]<<Q81[0];
            }else if(valnROX>ALN22&&valnROX<=ALN23){
                row_data<<Q82[1]<<Q82[2]<<Q82[3]<<Q82[0];
            }else if(valnROX>ALN23&&valnROX<=ALN24){
                row_data<<Q83[1]<<Q83[2]<<Q83[3]<<Q83[0];
            }else if(valnROX>ALN24){
                row_data<<Q84[1]<<Q84[2]<<XAL4+"ul"<<Q84[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&valnVIC/valnROX>DIN5&&valnVIC/valnROX<=DIN6){
            if(valnROX<ALN25&&valnVIC<ASN7){
                row_data<<Q92[1]<<Q92[2]<<Q92[3]<<Q92[0];
            }else if(valnROX<ALN25&&valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }else if(valnROX>=ALN25&&valnROX<=ALN26){
                row_data<<Q94[1]<<Q94[2]<<Q94[3]<<Q94[0];
            }else if(valnROX>ALN26&&valnROX<=ALN27){
                row_data<<Q95[1]<<Q95[2]<<Q95[3]<<Q95[0];
            }else if(valnROX>ALN27&&valnROX<=ALN28){
                row_data<<Q96[1]<<Q96[2]<<Q96[3]<<Q96[0];
            }else if(valnROX>ALN28&&valnROX<=ALN29){
                row_data<<Q97[1]<<Q97[2]<<Q97[3]<<Q97[0];
            }else if(valnROX>ALN29&&valnROX<=ALN30){
                row_data<<Q98[1]<<Q98[2]<<Q98[3]<<Q98[0];
            }else if(valnROX>ALN30){
                row_data<<Q99[1]<<Q99[2]<<XAL5+"ul"<<Q99[0];
            }
        }else if(valnCY5C-valCJ<ICS1&&(valnVIC/valnROX>DIN6||valnVIC/valnROX==0)){
            if(valnVIC<ASN7){
                row_data<<Q85[1]<<Q85[2]<<Q85[3]<<Q85[0];
            }else if(valnVIC>=ASN7){
                if(valnVIC>=ASN8&&valnVIC<=ASN9){
                    row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                    row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                    row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                    row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
                }else if(valnVIC>ASN12){
                    row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
                }
            }
        }else if(valnCY5C-valCJ>=ICS1){
            row_data<<Q45[1]<<Q45[2]<<Q45[3]<<Q45[0];
        }else{
            row_data<<"-"<<"-"<<"-"<<"-";
        }
    }else{
        int xAS1 = qRound(5*(valnVIC/0.5)-5);
        QString XAS1 = QString::number(xAS1);
        if(valnVIC<ASN7){
            row_data<<Q85[1]<<Q85[2]<<Q85[3]<<Q85[0];
        }else if(valnVIC>=ASN7){
            if(valnVIC>=ASN8&&valnVIC<=ASN9){
                row_data<<Q87[1]<<Q87[2]<<Q87[3]<<Q87[0]<<"二代测序上样方案见相应分表";
            }else if(valnVIC>ASN9&&valnVIC<=ASN10){
                row_data<<Q88[1]<<Q88[2]<<Q88[3]<<Q88[0]<<"二代测序上样方案见相应分表";
            }else if(valnVIC>ASN10&&valnVIC<=ASN11){
                row_data<<Q89[1]<<Q89[2]<<Q89[3]<<Q89[0]<<"二代测序上样方案见相应分表";
            }else if(valnVIC>ASN11&&valnVIC<=ASN12){
                row_data<<Q90[1]<<Q90[2]<<Q90[3]<<Q90[0]<<"二代测序上样方案见相应分表";
            }else if(valnVIC>ASN12){
                row_data<<Q91[1]<<Q91[2]<<XAS1+"ul"<<Q91[0]<<"二代测序上样方案见相应分表";
            }
        }
    }
    return row_data;
}

// 总数等值初始化计算
void DataAnalysisWindow::numlu()
{
    int sum=0,xs=0,ynum=0,mininum=0,ednum=0,renum=0;

    for(int i=0;i<ui->tableWidget->rowCount();i++){
        if(ui->tableWidget->item(i,2)->text()!="标准品"){
            sum+=1;
        }
    }
    ui->pushButton_7->setText("总数："+QString::number(sum/4));
    for(int i=0;i<ui->tableWidget->rowCount();i+=4){
        if(ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,15)->text().contains("ul")){
            xs+=1;
        }
    }
    ui->pushButton_13->setText("需稀释样本数量："+QString::number(xs));
    for(int i=0;i<ui->tableWidget->rowCount();i+=4){
        if(ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,13)->text().contains("Y-STR")){
            ynum+=1;
        }
    }
    ui->pushButton_12->setText("Y-STR："+QString::number(ynum));
    for(int i=0;i<ui->tableWidget->rowCount();i+=4){
        if(ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,13)->text().contains("mini-STR")){
            mininum+=1;
        }
    }
    ui->pushButton_8->setText("mini-STR："+QString::number(mininum));
    for(int i=0;i<ui->tableWidget->rowCount();i+=4){
        if(ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,13)->text().contains("二代测序")){
            ednum+=1;
        }
    }
    ui->pushButton_11->setText("二代测序数量："+QString::number(ednum));
    for(int i=0;i<ui->tableWidget->rowCount();i+=4){
        if(ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,13)->text().contains("重新提取")){
            renum+=1;
        }
    }
    ui->pushButton_14->setText("重新提取数量："+QString::number(renum));
}

//标准曲线FAM显示隐藏
void DataAnalysisWindow::on_FAMCheckBox_clicked(bool checked)
{
    if(ui->comboBox->currentText()=="标准曲线"){
        if(checked){
            bzFAM->setVisible(true);
            bzsdFAM->setVisible(true);
            fbzFAM->setVisible(true);
            QLegend *legend = myChart->legend();
            if (legend) {
                // 获取图例标记数组
                QList<QLegendMarker*> markers = legend->markers();
                if (!markers.isEmpty()) {
                    // 隐藏第一个系列的图例项
                    for(int i=4;i<12;i++){
                        markers[i]->setVisible(false);
                    }
                }
            }
        }else{
            bzFAM->setVisible(false);
            bzsdFAM->setVisible(false);
            fbzFAM->setVisible(false);
        }
    }
}

//标准曲线VIC显示隐藏
void DataAnalysisWindow::on_VICCheckBox_clicked(bool checked)
{
    if(ui->comboBox->currentText()=="标准曲线"){
        if(checked){
            bzVIC->setVisible(true);
            bzsdVIC->setVisible(true);
            fbzVIC->setVisible(true);
            QLegend *legend = myChart->legend();
            if (legend) {
                // 获取图例标记数组
                QList<QLegendMarker*> markers = legend->markers();
                if (!markers.isEmpty()) {
                    // 隐藏第一个系列的图例项
                    for(int i=4;i<12;i++){
                        markers[i]->setVisible(false);
                    }
                }
            }
        }else{
            bzVIC->setVisible(false);
            bzsdVIC->setVisible(false);
            fbzVIC->setVisible(false);
        }
    }
}

//标准曲线ROX显示隐藏
void DataAnalysisWindow::on_ROXCheckBox_clicked(bool checked)
{
    if(ui->comboBox->currentText()=="标准曲线"){
        if(checked){
            bzROX->setVisible(true);
            bzsdROX->setVisible(true);
            fbzROX->setVisible(true);QLegend *legend = myChart->legend();
            if (legend) {
                // 获取图例标记数组
                QList<QLegendMarker*> markers = legend->markers();
                if (!markers.isEmpty()) {
                    // 隐藏第一个系列的图例项
                    for(int i=4;i<12;i++){
                        markers[i]->setVisible(false);
                    }
                }
            }
        }else{
            bzROX->setVisible(false);
            bzsdROX->setVisible(false);
            fbzROX->setVisible(false);
        }
    }
}

//标准曲线CY5显示隐藏
void DataAnalysisWindow::on_CY5CheckBox_clicked(bool checked)
{
    if(ui->comboBox->currentText()=="标准曲线"){
        if(checked){
            bzCY5->setVisible(true);
            bzsdCY5->setVisible(true);
            fbzCY5->setVisible(true);
            QLegend *legend = myChart->legend();
            if (legend) {
                // 获取图例标记数组
                QList<QLegendMarker*> markers = legend->markers();
                if (!markers.isEmpty()) {
                    // 隐藏第一个系列的图例项
                    for(int i=4;i<12;i++){
                        markers[i]->setVisible(false);
                    }
                }
            }
        }else{
            bzCY5->setVisible(false);
            bzsdCY5->setVisible(false);
            fbzCY5->setVisible(false);
        }
    }
}

// 筛选槽函数
void DataAnalysisWindow::on_clicked_leftmouse1(int flag)
{
    if(flag==1){
        for(int i=0;i<ui->tableWidget->rowCount();i++){
            ui->tableWidget->setRowHidden(i,false);
        }
    }else if(flag==2){
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if((ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,2)->text()!="IPC")&&ui->tableWidget->item(i,15)->text().contains("ul")){
                ui->tableWidget->setRowHidden(i,false);
            }else{
                ui->tableWidget->setRowHidden(i,true);
                ui->tableWidget->setRowHidden(i+1,true);
                ui->tableWidget->setRowHidden(i+2,true);
                ui->tableWidget->setRowHidden(i+3,true);
            }
        }
    }else if(flag==3){
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if((ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,2)->text()!="IPC")&&ui->tableWidget->item(i,13)->text().contains("Y-STR")){
                ui->tableWidget->setRowHidden(i,false);

            }else{
                ui->tableWidget->setRowHidden(i,true);
                ui->tableWidget->setRowHidden(i+1,true);
                ui->tableWidget->setRowHidden(i+2,true);
                ui->tableWidget->setRowHidden(i+3,true);
            }
        }
    }else if(flag==4){
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if((ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,2)->text()!="IPC")&&ui->tableWidget->item(i,13)->text().contains("mini-STR")){
                ui->tableWidget->setRowHidden(i,false);
            }else{
                ui->tableWidget->setRowHidden(i,true);
                ui->tableWidget->setRowHidden(i+1,true);
                ui->tableWidget->setRowHidden(i+2,true);
                ui->tableWidget->setRowHidden(i+3,true);
            }
        }
    }else if(flag==5){
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if((ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,2)->text()!="IPC")&&ui->tableWidget->item(i,13)->text().contains("二代测序")){
                ui->tableWidget->setRowHidden(i,false);
            }else{
                ui->tableWidget->setRowHidden(i,true);
                ui->tableWidget->setRowHidden(i+1,true);
                ui->tableWidget->setRowHidden(i+2,true);
                ui->tableWidget->setRowHidden(i+3,true);
            }
        }
    }else if(flag==6){
        for(int i=0;i<ui->tableWidget->rowCount();i+=4){
            if((ui->tableWidget->item(i,2)->text()!="标准品"&&ui->tableWidget->item(i,2)->text()!="IPC")&&ui->tableWidget->item(i,13)->text().contains("重新提取")){
                ui->tableWidget->setRowHidden(i,false);
            }else{
                ui->tableWidget->setRowHidden(i,true);
                ui->tableWidget->setRowHidden(i+1,true);
                ui->tableWidget->setRowHidden(i+2,true);
                ui->tableWidget->setRowHidden(i+3,true);
            }
        }
    }
}

void DataAnalysisWindow::on_pushButton_4_clicked()
{
    this->close();
    fxpzui->close();
    anscrui->close();
    refWindow=true;

    if(MainWindow::experimentStatus.get()==4){
        MainWindow::experimentStatus.set(0);
    }
    emit changeMainWindow();
}

// 下游加样表格导出 cnr 6.22
void DataAnalysisWindow::datao()
{
    QList<int> kongsxx;
    if(true){
        QString sql="select pos,SampleName,SampleType,AccessName from sampleInfo s "
                    "join SampleAccessInfo sa on s.ID = sa.SampleGuid "
                    " where sa.AccessName in ('FAM','VIC','ROX','CY5') "
                    "order by ColNum,RowNum;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.exec(sql);
        while (query.next()) {
            QString column1Value = query.value("pos").toString();
            QString column3Value = query.value("SampleName").toString();
            QString column4Value = query.value("SampleType").toString();
            QString column5Value = query.value("AccessName").toString();
            if(!column3Value.isEmpty()||!column4Value.isEmpty()||!column5Value.isEmpty()){
                if(!kongsxx.contains(column1Value.toInt())){
                    kongsxx.append(column1Value.toInt());
                }
            }
        }
    }

    // 检查目录是否存在，如果不存在则创建
    QDir dir;
    if (!dir.exists("./dataout/")){
        dir.mkpath("./dataout/"); // 创建目录，包括所有必要的上级目录
    }
    if (!dir.exists("./datao/")){
        dir.mkpath("./datao/"); // 创建目录，包括所有必要的上级目录
    }
    QString valna;
    QStringList konglist;
    char col = 'A';
    int row = 1;
    for(col='A';col<='F';col++){
        row=1;
        for(row;row<=4;row++){
            QString element = QString("%1%2").arg(col).arg(row);
            konglist.append(element);
        }
    }
    if(isYing){
        // 创建一个新的Excel文档
        QXlsx::Document xlsx;

        // 获取当前时间并转换为字符串
        QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
        QString fullPath3 = "./dataout/" + fileName3;
        QString fullPath4;
        if(doutfl!=1){
            QString directory1 = filep;
            fullPath4 = directory1 + "/"+fileName3;
        }else if(doutfl==1){
            QString directory1 = outpath;
            fullPath4 = directory1 + "/"+fileName3;
        }
        QFile file(fullPath3);
        QFile file2(fullPath4);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            // 处理文件打开失败的情况
            QMessageBox::critical(nullptr, "Error", "Could not open file for writing:" + file.errorString());
            return;
        }
        if (!file2.open(QIODevice::WriteOnly | QIODevice::Text)) {
            // 处理文件打开失败的情况
            QMessageBox::critical(nullptr, "Error", "Could not open file for writing:" + file2.errorString());
            return;
        }
        QTextStream out(&file);
        QTextStream out2(&file2);
        // 设置编码，如果需要的话，比如UTF-8
        out.setCodec("UTF-8");
        out2.setCodec("UTF-8");

        // 添加5个sheet页
        xlsx.addSheet("样本设置");
        xlsx.addSheet("原始数据");
        xlsx.addSheet("扩增数据");
        xlsx.addSheet("结果分析");
        xlsx.addSheet("下游加样表格");
        QString sql="SELECT ExperimentName,RunTime,FinishTime FROM ExperimentInfo";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        QStringList sanames;
        query.exec(sql);
        while (query.next()) {
            QString column1Value = query.value("ExperimentName").toString();
            QString column2Value = query.value("RunTime").toString();
            QString column3Value = query.value("FinishTime").toString();
            sanames.append(column1Value);
            sanames.append(column2Value);
            sanames.append(column3Value);
        }
        if(true){
            out<<QString("样本设置\n");
            out<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            out2<<QString("样本设置\n");
            out2<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out2<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out2<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out2<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            xlsx.selectSheet("样本设置");
            xlsx.write(1,1,"仪器名称");
            xlsx.write(2,1,"创建日期");
            xlsx.write(3,1,"实验名称");
            xlsx.write(4,1,"实验结束时间");
            xlsx.write(1,2,"card-type-chip");
            xlsx.write(2,2,sanames[1]);
            xlsx.write(3,2,sanames[0]);
            xlsx.write(4,2,sanames[2]);
            QStringList tit;
            tit<<"编号"<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"数量";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("数量\t");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("数量\t");
            for(int i=0;i<tit.length();i++){
                xlsx.write(6,i+1,tit[i]);
            }
            int num=7;
            bool flin;
            QStringList rowdata;
            for(int i=0;i<24;i++){
                flin=false;
                for(int j=0;j<ui->tableWidget->rowCount();j++){
                    if(konglist[i]==ui->tableWidget->item(j,1)->text()){
                        rowdata<<QString::number(i+1)<<konglist[i]<<ui->tableWidget->item(j,2)->text()<<ui->tableWidget->item(j,3)->text()<<ui->tableWidget->item(j,4)->text();
                        if(ui->tableWidget->item(j,3)->text()=="标准品"){
                            rowdata<<ui->tableWidget->item(j,6)->text();
                        }else{
                            rowdata<<" ";
                        }
                        for(int c=0;c<rowdata.length();c++){
                            xlsx.write(num,c+1,rowdata[c]);
                            out<<rowdata[c]<<"\t";
                            out2<<rowdata[c]<<"\t";
                        }
                        num++;
                        rowdata.clear();
                        out<<"\n";
                        out2<<"\n";
                        flin=true;
                    }
                }
                if(!flin){
                    //                    rowdata<<QString::number(i+1)<<konglist[i];
                    //                    for(int c=0;c<rowdata.length();c++){
                    //                        xlsx.write(num,c+1,rowdata[c]);
                    //                        out<<rowdata[c]<<"\t";
                    //                        out2<<rowdata[c]<<"\t";
                    //                    }
                    //                    num++;
                    //                    rowdata.clear();
                    //                    out<<",\n";
                    //                    out2<<",\n";
                }
            }
        }
        if(true){
            xlsx.selectSheet("原始数据");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("原始数据\n");
            out2<<QString("原始数据\n");
            QStringList tit;
            tit<<"孔位"<<"循环数"<<"FAM"<<"VIC"<<"ROX"<<"CY5";
            out<<QString("孔位\t")<<QString("循环数\t")<<QString("FAM\t")<<QString("VIC\t")<<QString("ROX\t")<<QString("CY5\n");
            out2<<QString("孔位\t")<<QString("循环数\t")<<QString("FAM\t")<<QString("VIC\t")<<QString("ROX\t")<<QString("CY5\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(1,i+1,tit[i]);
            }
            int xh = analyseClient->leh;
            for(int j=0;j<xh;j++){
                for(int i=0;i<konglist.length();i++){
                    if(!kongsxx.contains(i+1)){
                        continue;
                    }
                    xlsx.write(j*kongsxx.length()+i+2,1,konglist[i]);
                    xlsx.write(j*kongsxx.length()+i+2,2,j+1);
                }
            }
            QString islvv;
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            QString sql="Select * From DataAnalyseSetting";
            query.exec(sql);
            while(query.next()){
                islvv=query.value("isLv").toString();
            }
            QStringList kongw,xhs,famData,vicData,roxData,cy5Data;
            if(islvv=="0"){
                sql="SELECT PositionNumber,CyclesNumber,FAM,VIC,ROX,CY5 FROM FluorescenceLvBoData";
                query.exec(sql);
                while (query.next()) {
                    kongw.append(query.value("PositionNumber").toString());
                    xhs.append(query.value("CyclesNumber").toString());
                    famData.append(query.value("FAM").toString());
                    vicData.append(query.value("VIC").toString());
                    roxData.append(query.value("ROX").toString());
                    cy5Data.append(query.value("CY5").toString());
                }
            }else if(islvv=="1"){
                sql="SELECT PositionNumber,CyclesNumber,FAM,VIC,ROX,CY5 FROM FluorescenceData";
                query.exec(sql);
                while (query.next()) {
                    kongw.append(query.value("PositionNumber").toString());
                    xhs.append(query.value("CyclesNumber").toString());
                    famData.append(query.value("FAM").toString());
                    vicData.append(query.value("VIC").toString());
                    roxData.append(query.value("ROX").toString());
                    cy5Data.append(query.value("CY5").toString());
                }
            }


            QStringList bz96;
            for(int j=0;j<xh;j++){
                for(int i=1;i<97;i++){
                    bz96.append(QString::number(i));
                }
            }

            int flk=0,flh=0;
            for(int i=0;i<xh;i++){
                for(int j=0;j<24;j++){
                    if(!kongsxx.contains(j+1)){
                        flk++;
                    }else{
                        if(bz96[96*i+j]==kongw[flk]){
                            out<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<famData[flk]<<"\t"<<vicData[flk]<<"\t"<<roxData[flk]<<"\t"<<cy5Data[flk]<<"\n";
                            out2<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<famData[flk]<<"\t"<<vicData[flk]<<"\t"<<roxData[flk]<<"\t"<<cy5Data[flk]<<"\n";
                            if(islvv=="0"){
                                xlsx.write(flh+2,3,famData[flk].toDouble());
                                xlsx.write(flh+2,4,vicData[flk].toDouble());
                                xlsx.write(flh+2,5,roxData[flk].toDouble());
                                xlsx.write(flh+2,6,cy5Data[flk].toDouble());
                            }else if(islvv=="1"){
                                xlsx.write(flh+2,3,famData[flk].toInt());
                                xlsx.write(flh+2,4,vicData[flk].toInt());
                                xlsx.write(flh+2,5,roxData[flk].toInt());
                                xlsx.write(flh+2,6,cy5Data[flk].toInt());
                            }

                            if(flk==kongw.length()-1){

                            }else{
                                flk++;
                            }
                            flh++;
                        }else{
                            out<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\n";
                            out2<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\n";
                            xlsx.write(flh+2,3,"");
                            xlsx.write(flh+2,4,"");
                            xlsx.write(flh+2,5,"");
                            xlsx.write(flh+2,6,"");
                            flh++;
                        }
                    }
                }
            }
        }
        if(true){
            xlsx.selectSheet("扩增数据");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("扩增数据\n");
            out2<<QString("扩增数据\n");
            QStringList tit;
            tit<<"编号"<<"孔位"<<"循环数"<<"荧光染料"<<"Rn"<<"ΔRn";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("循环数\t")<<QString("荧光染料\t")<<QString("Rn\t")<<QString("ΔRn\n");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("循环数\t")<<QString("荧光染料\t")<<QString("Rn\t")<<QString("ΔRn\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(1,i+1,tit[i]);
            }
            int xh=analyseClient->leh;
            int flh=2;
            QStringList famrn,vicrn,roxrn,cy5rn;
            if(true){
                QString sql = QString("SELECT BaselineValue FROM FluorescenceResultTable WHERE AccessType='FAM'");
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                if (!query.exec(sql)) {
                    qDebug() << "Query failed:" << query.lastError().text();
                    return; // 或者其他错误处理
                }
                while (query.next()) {
                    famrn.append( query.value("BaselineValue").toString());
                }
            }
            if(true){
                QString sql = QString("SELECT BaselineValue FROM FluorescenceResultTable WHERE AccessType='VIC'");
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                if (!query.exec(sql)) {
                    qDebug() << "Query failed:" << query.lastError().text();
                    return; // 或者其他错误处理
                }
                while (query.next()) {
                    vicrn.append( query.value("BaselineValue").toString());
                }
            }
            if(true){
                QString sql = QString("SELECT BaselineValue FROM FluorescenceResultTable WHERE AccessType='ROX'");
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                if (!query.exec(sql)) {
                    qDebug() << "Query failed:" << query.lastError().text();
                    return; // 或者其他错误处理
                }
                while (query.next()) {
                    roxrn.append( query.value("BaselineValue").toString());
                }
            }
            if(true){
                QString sql = QString("SELECT BaselineValue FROM FluorescenceResultTable WHERE AccessType='CY5'");
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                if (!query.exec(sql)) {
                    qDebug() << "Query failed:" << query.lastError().text();
                    return; // 或者其他错误处理
                }
                while (query.next()) {
                    cy5rn.append( query.value("BaselineValue").toString());
                }
            }
            for(int i=0;i<24;i++){
                if(!kongsxx.contains(i+1)){
                    //                    flh++;
                    continue;
                }
                for(int j=0;j<xh*4;j++){
                    if(j<xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1);
                        xlsx.write(flh,4,"FAM");
                        QString sql=QString("SELECT FAM FROM FluorescenceLvData WHERE PositionNumber=%1 AND CyclesNumber=%2").arg(i+1).arg(j+1);
                        QSqlDatabase db = dbHelper::openConnection();
                        QSqlQuery query(db);
                        QString drn;
                        if (!query.exec(sql)){
                            qDebug() << "Query failed:" << query.lastError().text();
                            return; // 或者其他错误处理
                        }
                        while (query.next()) {
                            drn = query.value("FAM").toString();
                        }
                        qDebug()<<drn;
                        xlsx.write(flh,6,QString::number(drn.toDouble(),'f',2).toDouble());
                        xlsx.write(flh,5,QString::number(drn.toDouble()+famrn[i].toDouble(),'f',2).toDouble());
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1)<<"\t";
                        out2<<QString::number(j+1)<<"\t";
                        out<<"FAM"<<"\t";
                        out2<<"FAM"<<"\t";
                        out<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out<<QString::number(drn.toDouble()+famrn[i].toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble()+famrn[i].toDouble(),'f',2)<<"\t";
                        flh++;
                    }else if(j>=xh&&j<2*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-xh);
                        xlsx.write(flh,4,"VIC");
                        QString sql=QString("SELECT VIC FROM FluorescenceLvData WHERE PositionNumber=%1 AND CyclesNumber=%2").arg(i+1).arg(j+1-xh);
                        QSqlDatabase db = dbHelper::openConnection();
                        QSqlQuery query(db);
                        QString drn;
                        query.exec(sql);
                        while (query.next()) {
                            QString column1Value;
                            column1Value = query.value("VIC").toString();
                            drn=column1Value;
                            qDebug()<<drn;
                        }
                        xlsx.write(flh,6,QString::number(drn.toDouble(),'f',2).toDouble());
                        xlsx.write(flh,5,QString::number(drn.toDouble()+vicrn[i].toDouble(),'f',2).toDouble());
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-xh)<<"\t";
                        out2<<QString::number(j+1-xh)<<"\t";
                        out<<"VIC"<<"\t";
                        out2<<"VIC"<<"\t";
                        out<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out<<QString::number(drn.toDouble()+vicrn[i].toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble()+vicrn[i].toDouble(),'f',2)<<"\t";
                        flh++;
                    }else if(j>=2*xh&&j<3*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-2*xh);
                        xlsx.write(flh,4,"ROX");
                        QString sql=QString("SELECT ROX FROM FluorescenceLvData WHERE PositionNumber=%1 AND CyclesNumber=%2").arg(i+1).arg(j+1-2*xh);
                        QSqlDatabase db = dbHelper::openConnection();
                        QSqlQuery query(db);
                        QString drn;
                        query.exec(sql);
                        while (query.next()) {
                            drn = query.value("ROX").toString();
                        }
                        xlsx.write(flh,6,QString::number(drn.toDouble(),'f',2).toDouble());
                        xlsx.write(flh,5,QString::number(drn.toDouble()+roxrn[i].toDouble(),'f',2).toDouble());
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-2*xh)<<"\t";
                        out2<<QString::number(j+1-2*xh)<<"\t";
                        out<<"ROX"<<"\t";
                        out2<<"ROX"<<"\t";
                        out<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out<<QString::number(drn.toDouble()+roxrn[i].toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble()+roxrn[i].toDouble(),'f',2)<<"\t";
                        flh++;
                    }else if(j>=3*xh&&j<4*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-3*xh);
                        xlsx.write(flh,4,"CY5");
                        QString sql=QString("SELECT CY5 FROM FluorescenceLvData WHERE PositionNumber=%1 AND CyclesNumber=%2").arg(i+1).arg(j+1-3*xh);
                        QSqlDatabase db = dbHelper::openConnection();
                        QSqlQuery query(db);
                        QString drn;
                        query.exec(sql);
                        while (query.next()) {
                            drn = query.value("CY5").toString();
                        }
                        xlsx.write(flh,6,QString::number(drn.toDouble(),'f',2).toDouble());
                        xlsx.write(flh,5,QString::number(drn.toDouble()+cy5rn[i].toDouble(),'f',2).toDouble());
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-3*xh)<<"\t";
                        out2<<QString::number(j+1-3*xh)<<"\t";
                        out<<"CY5"<<"\t";
                        out2<<"CY5"<<"\t";
                        out<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble(),'f',2)<<"\t";
                        out<<QString::number(drn.toDouble()+cy5rn[i].toDouble(),'f',2)<<"\t";
                        out2<<QString::number(drn.toDouble()+cy5rn[i].toDouble(),'f',2)<<"\t";
                        flh++;
                    }
                }
            }
        }
        if(true){
            xlsx.selectSheet("结果分析");
            xlsx.write(1,1,"仪器名称");
            xlsx.write(2,1,"创建日期");
            xlsx.write(3,1,"实验名称");
            xlsx.write(4,1,"实验结束时间");
            xlsx.write(1,2,"card-type-chip");
            xlsx.write(2,2,sanames[1]);
            xlsx.write(3,2,sanames[0]);
            xlsx.write(4,2,sanames[2]);
            out<<QString("结果分析\n");
            out2<<QString("结果分析\n");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            out2<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out2<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out2<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out2<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            QStringList tit;
            tit<<"编号"<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT"<<"CT平均值"<<"浓度"<<"浓度平均值"<<"y轴截距"<<"R²"<<"斜率"<<"扩增效率";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("CT\t")<<QString("CT平均值\t")<<QString("浓度\t")<<QString("浓度平均值\t")<<QString("y轴截距\t")<<QString("R²\t")<<QString("斜率\t")<<QString("扩增效率\n");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("CT\t")<<QString("CT平均值\t")<<QString("浓度\t")<<QString("浓度平均值\t")<<QString("y轴截距\t")<<QString("R²\t")<<QString("斜率\t")<<QString("扩增效率\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(6,i+1,tit[i]);
            }
            QString kong,sample,tetype,lu,cq,cqt,qya,quaM;
            for(int i=0;i<ui->tableWidget->rowCount();i++){
                kong=ui->tableWidget->item(i,1)->text();
                sample=ui->tableWidget->item(i,2)->text();
                tetype=ui->tableWidget->item(i,3)->text();
                lu=ui->tableWidget->item(i,4)->text();
                cq=ui->tableWidget->item(i,5)->text();
                qya=ui->tableWidget->item(i,6)->text();
                xlsx.write(i+7,1,i+1);
                xlsx.write(i+7,2,kong);
                xlsx.write(i+7,3,sample);
                xlsx.write(i+7,4,tetype);
                xlsx.write(i+7,5,lu);
                xlsx.write(i+7,6,cq.toDouble());
                if(lu=="FAM"){
                    xlsx.write(i+7,7,CQMeanF.value(sample));
                }else if(lu=="VIC"){
                    xlsx.write(i+7,7,CQMeanV.value(sample));
                }else if(lu=="ROX"){
                    xlsx.write(i+7,7,CQMeanR.value(sample));
                }else if(lu=="CY5"){
                    xlsx.write(i+7,7,CQMeanC.value(sample));
                }
                xlsx.write(i+7,8,qya.toDouble());
                if(MainWindow::isBzsy){
                    xlsx.write(i+7,9,qut[i].toDouble());
                }else{
                    xlsx.write(i+7,9," ");
                }

            }
            if(MainWindow::isBzsy){
                for(int i=0;i<ui->tableWidget->rowCount();i+=4){
                    xlsx.write(i+10,10,QString::number(bcy5,'f',2).toDouble());
                    xlsx.write(i+10,11,QString::number(r2cy5,'f',2).toDouble());
                    xlsx.write(i+10,12,QString::number(kcy5,'f',2).toDouble());
                    xlsx.write(i+10,13,QString::number(cucy5,'f',2)+"%");
                    xlsx.write(i+7,10,QString::number(bfam,'f',2).toDouble());
                    xlsx.write(i+7,11,QString::number(r2fam,'f',2).toDouble());
                    xlsx.write(i+7,12,QString::number(kfam,'f',2).toDouble());
                    xlsx.write(i+7,13,QString::number(cufam,'f',2)+"%");
                    xlsx.write(i+8,10,QString::number(brox,'f',2).toDouble());
                    xlsx.write(i+8,11,QString::number(r2rox,'f',2).toDouble());
                    xlsx.write(i+8,12,QString::number(krox,'f',2).toDouble());
                    xlsx.write(i+8,13,QString::number(curox,'f',2)+"%");
                    xlsx.write(i+9,10,QString::number(bvic,'f',2).toDouble());
                    xlsx.write(i+9,11,QString::number(r2vic,'f',2).toDouble());
                    xlsx.write(i+9,12,QString::number(kvic,'f',2).toDouble());
                    xlsx.write(i+9,13,QString::number(cuvic,'f',2)+"%");
                }
            }else{
                for(int i=7;i<ui->tableWidget->rowCount()+7;i++){
                    for (int j=10;j<14;j++) {
                        xlsx.write(i,j," ");
                    }
                }
            }

            for(int i=0;i<ui->tableWidget->rowCount();i++){
                kong=ui->tableWidget->item(i,0)->text();
                kong=ui->tableWidget->item(i,1)->text();
                sample=ui->tableWidget->item(i,2)->text();
                tetype=ui->tableWidget->item(i,3)->text();
                lu=ui->tableWidget->item(i,4)->text();
                cq=ui->tableWidget->item(i,5)->text();
                qya=ui->tableWidget->item(i,6)->text();
                out<<kong<<"\t";
                out<<sample<<"\t";
                out<<tetype<<"\t";
                out<<lu<<"\t";
                out<<cq<<"\t";
                out<<qya<<"\t";
                if(MainWindow::isBzsy){
                    out<<qut[i]<<"\t";
                }else{
                    out<<" "<<"\t";
                }
                out2<<kong<<"\t";
                out2<<sample<<"\t";
                out2<<tetype<<"\t";
                out2<<lu<<"\t";
                out2<<cq<<"\t";
                out2<<qya<<"\t";
                if(MainWindow::isBzsy){
                    out2<<qut[i]<<"\t";
                }else{
                    out2<<" "<<"\t";
                }
                if((i+1)%4==1){
                    out<<QString::number(bfam)<<"\t"<<QString::number(r2fam)<<"\t"<<QString::number(kfam)<<"\t"<<QString::number(cufam)<<"\n";
                    out2<<QString::number(bfam)<<"\t"<<QString::number(r2fam)<<"\t"<<QString::number(kfam)<<"\t"<<QString::number(cufam)<<"\n";
                }else if((i+1)%4==2){
                    out<<QString::number(brox)<<"\t"<<QString::number(r2rox)<<"\t"<<QString::number(krox)<<"\t"<<QString::number(curox)<<"\n";
                    out2<<QString::number(brox)<<"\t"<<QString::number(r2rox)<<"\t"<<QString::number(krox)<<"\t"<<QString::number(curox)<<"\n";
                }else if((i+1)%4==3){
                    out<<QString::number(bvic)<<"\t"<<QString::number(r2vic)<<"\t"<<QString::number(kvic)<<"\t"<<QString::number(cuvic)<<"\n";
                    out2<<QString::number(bvic)<<"\t"<<QString::number(r2vic)<<"\t"<<QString::number(kvic)<<"\t"<<QString::number(cuvic)<<"\n";
                }else if((i+1)%4==0){
                    out<<QString::number(bcy5)<<"\t"<<QString::number(r2cy5)<<"\t"<<QString::number(kcy5)<<"\t"<<QString::number(cucy5)<<"\n";
                    out2<<QString::number(bcy5)<<"\t"<<QString::number(r2cy5)<<"\t"<<QString::number(kcy5)<<"\t"<<QString::number(cucy5)<<"\n";
                }
            }
        }
        if(true){
            xlsx.selectSheet("下游加样表格");
            for(int i=0;i<15;i++){
                xlsx.setColumnWidth(i+1,18);
            }
            for(int i=0;i<32;i++){
                xlsx.setRowHeight(i+1,22);
            }
            // 创建一个Format对象
            QXlsx::Format format2;
            format2.setBorderStyle(QXlsx::Format::BorderMedium);
            format2.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            QXlsx::Format format;
            format.setPatternBackgroundColor(QColor(152, 245, 255));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(1,1,"常-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(1,i+2,"",format);
            }
            format.setPatternBackgroundColor(QColor(0, 255, 0));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(12,1,"Y-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(12,i+2,"",format);
            }
            format.setPatternBackgroundColor(QColor(255, 255, 0));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(23,1,"mini-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(23,i+2,"",format);
            }
            int zmfl=3;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            zmfl=14;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            zmfl=25;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            for(int i=1;i<5;i++){
                xlsx.write(2,i+1,QString::number(i),format2);
                xlsx.write(13,i+1,QString::number(i),format2);
                xlsx.write(24,i+1,QString::number(i),format2);
            }
            QString L="";
            QString N="";
            QString LN="";
            QStringList hang,lie;
            for(int i=2;i<6;i++){
                hang.append(QString::number(i-1));
            }
            for(char kong1='A';kong1<='F';kong1++){
                lie.append(QString(kong1));
            }

            for(int i=3;i<9;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-3];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="常STR"||ui->tableWidget->item(k,13)->text()=="常STR+Y-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }
            }
            for(int i=9;i<12;i++){
                for(int j=1;j<6;j++){
                    xlsx.write(i,j,"",format2);
                }
            }
            for(int i=14;i<20;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-14];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="常STR+Y-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }
            }
            for(int i=20;i<23;i++){
                for(int j=1;j<6;j++){
                    xlsx.write(i,j,"",format2);
                }
            }
            for(int i=25;i<31;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-25];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="二代测序或mini-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }
            }
        }
        if(isc=="1"){
            QString directory = "./dataout";
            if(doutfl==1){
                directory=outpath;
            }
            QDir dir;
            if (!dir.exists(directory)) {
                dir.mkpath(directory); // 创建目录
            }
            QString fullPath = directory + "/" + fileName;
            QString fullPath2 = directory + "/" + fileName2;

            if (xlsx.saveAs(fullPath)) {
                qDebug() << "文件保存成功：" << fullPath;

            } else {
                qDebug() << "文件保存失败";
            }
            if (xlsx.saveAs(fullPath2)) {
                qDebug() << "文件保存成功：" << fullPath2;
            } else {
                qDebug() << "文件保存失败";
            }
            // 关闭文件
            file.close();
            file2.close();
            if(doutfl!=1){
                QString directory1 = filep;
                if(filep!=""){
                    QDir dir1;
                    if (!dir1.exists(directory1)) {
                        dir1.mkpath(directory1); // 创建目录
                    }
                    QString fullPath = directory1 + "/" + fileName;
                    QString fullPath2 = directory1 + "/" + fileName2;

                    if (xlsx.saveAs(fullPath)) {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","treat","导出成功！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    } else {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","error","导出失败！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    }
                    if (xlsx.saveAs(fullPath2)) {
                    } else {
                    }
                }
            }
            if(doutfl==1){
                QString directory1 = outpath;
                if(filep!=""){
                    QDir dir1;
                    if (!dir1.exists(directory1)) {
                        dir1.mkpath(directory1); // 创建目录
                    }
                    QString fullPath = directory1 + "/" + fileName;
                    QString fullPath2 = directory1 + "/" + fileName2;
                    QString fullPath4 = directory1 + "/" + "_test.txt";
                    if (xlsx.saveAs(fullPath)) {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","treat","导出成功！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    } else {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","error","导出失败！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    }
                    if (xlsx.saveAs(fullPath2)) {
                    } else {
                    }
                }
            }
        }
    }else{
        //        QMessageBox::warning(nullptr, tr("警告"), tr("请确认表格中是否有数据;"), QMessageBox::Yes);
        // 创建一个新的Excel文档
        QXlsx::Document xlsx;
        // 获取当前时间并转换为字符串
        QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
        QString fullPath3 = "./dataout/" + fileName3;
        QString fullPath4;
        if(doutfl!=1){
            QString directory1 = filep;
            fullPath4 = directory1 + "/"+fileName3;
        }else if(doutfl==1){
            QString directory1 = outpath;
            fullPath4 = directory1 + "/"+fileName3;
        }
        QFile file(fullPath3);
        QFile file2(fullPath4);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            // 处理文件打开失败的情况
            QMessageBox::critical(nullptr, "Error", "Could not open file for writing:" + file.errorString());
            return;
        }
        if (!file2.open(QIODevice::WriteOnly | QIODevice::Text)) {
            // 处理文件打开失败的情况
            QMessageBox::critical(nullptr, "Error", "Could not open file for writing:" + file2.errorString());
            return;
        }
        QTextStream out(&file);
        QTextStream out2(&file2);
        // 设置编码，如果需要的话，比如UTF-8
        out.setCodec("UTF-8");
        out2.setCodec("UTF-8");

        // 添加5个sheet页
        xlsx.addSheet("样本设置");
        xlsx.addSheet("原始数据");
        xlsx.addSheet("扩增数据");
        xlsx.addSheet("结果分析");
        xlsx.addSheet("下游加样表格");
        QString sql="SELECT ExperimentName,RunTime,FinishTime FROM ExperimentInfo";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        QStringList sanames;
        query.exec(sql);
        while (query.next()) {
            QString column1Value = query.value("ExperimentName").toString();
            QString column2Value = query.value("RunTime").toString();
            QString column3Value = query.value("FinishTime").toString();
            sanames.append(column1Value);
            sanames.append(column2Value);
            sanames.append(column3Value);
        }
        if(true){
            out<<QString("样本设置\n");
            out<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            out2<<QString("样本设置\n");
            out2<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out2<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out2<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out2<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            xlsx.selectSheet("样本设置");
            xlsx.write(1,1,"仪器名称");
            xlsx.write(2,1,"创建日期");
            xlsx.write(3,1,"实验名称");
            xlsx.write(4,1,"实验结束时间");
            xlsx.write(1,2,"card-type-chip");
            xlsx.write(2,2,sanames[1]);
            xlsx.write(3,2,sanames[0]);
            xlsx.write(4,2,sanames[2]);
            QStringList tit;
            tit<<"编号"<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"数量";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("数量\t");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("数量\t");
            for(int i=0;i<tit.length();i++){
                xlsx.write(6,i+1,tit[i]);
            }
            int num=7;
            bool flin;
            QStringList rowdata;
            for(int i=0;i<24;i++){
                flin=false;
                for(int j=0;j<ui->tableWidget->rowCount();j++){
                    if(konglist[i]==ui->tableWidget->item(j,1)->text()){
                        rowdata<<QString::number(i+1)<<konglist[i]<<ui->tableWidget->item(j,2)->text()<<ui->tableWidget->item(j,3)->text()<<ui->tableWidget->item(j,4)->text();
                        if(ui->tableWidget->item(j,3)->text()=="标准品"){
                            rowdata<<ui->tableWidget->item(j,6)->text();
                        }
                        for(int c=0;c<rowdata.length();c++){
                            xlsx.write(num,c+1,rowdata[c]);
                            out<<rowdata[c]<<"\t";
                            out2<<rowdata[c]<<"\t";
                        }
                        num++;
                        rowdata.clear();
                        out<<"\n";
                        out2<<"\n";
                        flin=true;
                    }
                }
                if(!flin){
                    //                    rowdata<<QString::number(i+1)<<konglist[i];
                    //                    for(int c=0;c<rowdata.length();c++){
                    //                        xlsx.write(num,c+1,rowdata[c]);
                    //                        out<<rowdata[c]<<"\t";
                    //                        out2<<rowdata[c]<<"\t";
                    //                    }
                    //                    num++;
                    //                    rowdata.clear();
                    //                    out<<",\n";
                    //                    out2<<",\n";
                }
            }
        }
        if(true){
            xlsx.selectSheet("原始数据");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("原始数据\n");
            out2<<QString("原始数据\n");
            QStringList tit;
            tit<<"孔位"<<"循环数"<<"FAM"<<"VIC"<<"ROX"<<"CY5";
            out<<QString("孔位\t")<<QString("循环数\t")<<QString("FAM\t")<<QString("VIC\t")<<QString("ROX\t")<<QString("CY5\n");
            out2<<QString("孔位\t")<<QString("循环数\t")<<QString("FAM\t")<<QString("VIC\t")<<QString("ROX\t")<<QString("CY5\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(1,i+1,tit[i]);
            }
            int xh = analyseClient->leh;
            for(int j=0;j<xh;j++){
                for(int i=0;i<konglist.length();i++){
                    if(!kongsxx.contains(i+1)){
                        continue;
                    }
                    xlsx.write(j*24+i+2,1,konglist[i]);
                    xlsx.write(j*24+i+2,2,j+1);
                }
            }

            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);

            QString sql="SELECT PositionNumber,CyclesNumber FROM FluorescenceData";
            query.exec(sql);
            QStringList kongw,xhs;
            while (query.next()) {
                kongw.append(query.value("PositionNumber").toString());
                xhs.append(query.value("CyclesNumber").toString());
            }

            QStringList bz96;
            for(int j=0;j<xh;j++){
                for(int i=1;i<97;i++){
                    bz96.append(QString::number(i));
                }
            }

            int flk=0,flh=0;
            for(int i=0;i<xh;i++){
                for(int j=0;j<24;j++){
                    if(!kongsxx.contains(j+1)){
                        flk++;
                    }else{
                        if(false){
                            out<<konglist[j]<<"\t"<<QString::number(i+1)<<"\n";
                            out2<<konglist[j]<<"\t"<<QString::number(i+1)<<"\n";
                            if(flk==kongw.length()-1){

                            }else{
                                flk++;
                            }
                            flh++;
                        }else{
                            out<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\n";
                            out2<<konglist[j]<<"\t"<<QString::number(i+1)<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\t"<<" "<<"\n";
                            xlsx.write(flh+2,3,"");
                            xlsx.write(flh+2,4,"");
                            xlsx.write(flh+2,5,"");
                            xlsx.write(flh+2,6,"");
                            flh++;
                        }
                    }
                }
            }
        }
        if(true){
            xlsx.selectSheet("扩增数据");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("扩增数据\n");
            out2<<QString("扩增数据\n");
            QStringList tit;
            tit<<"编号"<<"孔位"<<"循环数"<<"荧光染料"<<"Rn"<<"ΔRn";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("循环数\t")<<QString("荧光染料\t")<<QString("Rn\t")<<QString("ΔRn\n");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("循环数\t")<<QString("荧光染料\t")<<QString("Rn\t")<<QString("ΔRn\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(1,i+1,tit[i]);
            }
            int xh=analyseClient->leh;
            int flh=2;
            QStringList famrn,vicrn,roxrn,cy5rn;
            for(int i=0;i<24;i++){
                if(!kongsxx.contains(i+1)){
                    continue;
                }
                for(int j=0;j<xh*4;j++){
                    if(j<xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1);
                        xlsx.write(flh,4,"FAM");
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1)<<"\t";
                        out2<<QString::number(j+1)<<"\t";
                        out<<"FAM"<<"\t";
                        out2<<"FAM"<<"\t";
                        flh++;
                    }else if(j>=xh&&j<2*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-xh);
                        xlsx.write(flh,4,"VIC");
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-xh)<<"\t";
                        out2<<QString::number(j+1-xh)<<"\t";
                        out<<"VIC"<<"\t";
                        out2<<"VIC"<<"\t";
                        flh++;
                    }else if(j>=2*xh&&j<3*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-2*xh);
                        xlsx.write(flh,4,"ROX");
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-2*xh)<<"\t";
                        out2<<QString::number(j+1-2*xh)<<"\t";
                        out<<"ROX"<<"\t";
                        out2<<"ROX"<<"\t";
                        flh++;
                    }else if(j>=3*xh&&j<4*xh){
                        xlsx.write(flh,1,i+1);
                        xlsx.write(flh,2,konglist[i]);
                        xlsx.write(flh,3,j+1-3*xh);
                        xlsx.write(flh,4,"CY5");
                        out<<QString::number(i+1)<<"\t";
                        out2<<QString::number(i+1)<<"\t";
                        out<<konglist[i]<<"\t";
                        out2<<konglist[i]<<"\t";
                        out<<QString::number(j+1-3*xh)<<"\t";
                        out2<<QString::number(j+1-3*xh)<<"\t";
                        out<<"CY5"<<"\t";
                        out2<<"CY5"<<"\t";
                        flh++;
                    }
                }
            }
        }
        if(true){
            xlsx.selectSheet("结果分析");
            xlsx.write(1,1,"仪器名称");
            xlsx.write(2,1,"创建日期");
            xlsx.write(3,1,"实验名称");
            xlsx.write(4,1,"实验结束时间");
            xlsx.write(1,2,"card-type-chip");
            xlsx.write(2,2,sanames[1]);
            xlsx.write(3,2,sanames[0]);
            xlsx.write(4,2,sanames[2]);
            out<<QString("结果分析\n");
            out2<<QString("结果分析\n");
            out<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out2<<"\n"<<"\n"<<"\n"<<"\n"<<"\n";
            out<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            out2<<QString("仪器名称\t")<<QString("card-type-chip\n");
            out2<<QString("创建日期\t")<<QString(sanames[1]+"\n");
            out2<<QString("实验名称\t")<<QString(sanames[0]+"\n");
            out2<<QString("实验结束时间\t")<<QString(sanames[2]+"\n");
            QStringList tit;
            tit<<"编号"<<"孔位"<<"样本名称"<<"样本类型"<<"荧光染料"<<"CT"<<"CT平均值"<<"浓度"<<"浓度平均值"<<"y轴截距"<<"R²"<<"斜率"<<"扩增效率";
            out<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("CT\t")<<QString("CT平均值\t")<<QString("浓度\t")<<QString("浓度平均值\t")<<QString("y轴截距\t")<<QString("R²\t")<<QString("斜率\t")<<QString("扩增效率\n");
            out2<<QString("编号\t")<<QString("孔位\t")<<QString("样本名称\t")<<QString("样本类型\t")<<QString("荧光染料\t")<<QString("CT\t")<<QString("CT平均值\t")<<QString("浓度\t")<<QString("浓度平均值\t")<<QString("y轴截距\t")<<QString("R²\t")<<QString("斜率\t")<<QString("扩增效率\n");
            for(int i=0;i<tit.length();i++){
                xlsx.write(6,i+1,tit[i]);
            }
            QString kong,sample,tetype,lu,cq,cqt,qya,quaM;
            for(int i=0;i<ui->tableWidget->rowCount();i++){
                kong=ui->tableWidget->item(i,1)->text();
                sample=ui->tableWidget->item(i,2)->text();
                tetype=ui->tableWidget->item(i,3)->text();
                lu=ui->tableWidget->item(i,4)->text();
                cq=ui->tableWidget->item(i,5)->text();
                qya=ui->tableWidget->item(i,6)->text();
                xlsx.write(i+7,1,i+1);
                xlsx.write(i+7,2,kong);
                xlsx.write(i+7,3,sample);
                xlsx.write(i+7,4,tetype);
                xlsx.write(i+7,5,lu);
                xlsx.write(i+7,6,cq.toDouble());
                if(lu=="FAM"){
                    xlsx.write(i+7,7,CQMeanF.value(sample));
                }else if(lu=="VIC"){
                    xlsx.write(i+7,7,CQMeanV.value(sample));
                }else if(lu=="ROX"){
                    xlsx.write(i+7,7,CQMeanR.value(sample));
                }else if(lu=="CY5"){
                    xlsx.write(i+7,7,CQMeanC.value(sample));
                }
                xlsx.write(i+7,8,qya.toDouble());
                if(MainWindow::isBzsy){
                    xlsx.write(i+7,9,qut[i].toDouble());
                }else{
                    xlsx.write(i+7,9," ");
                }
            }
            if(MainWindow::isBzsy){
                for(int i=0;i<ui->tableWidget->rowCount();i+=4){
                    xlsx.write(i+10,10,QString::number(bcy5,'f',2).toDouble());
                    xlsx.write(i+10,11,QString::number(r2cy5,'f',2).toDouble());
                    xlsx.write(i+10,12,QString::number(kcy5,'f',2).toDouble());
                    xlsx.write(i+10,13,QString::number(cucy5,'f',2)+"%");
                    xlsx.write(i+7,10,QString::number(bfam,'f',2).toDouble());
                    xlsx.write(i+7,11,QString::number(r2fam,'f',2).toDouble());
                    xlsx.write(i+7,12,QString::number(kfam,'f',2).toDouble());
                    xlsx.write(i+7,13,QString::number(cufam,'f',2)+"%");
                    xlsx.write(i+8,10,QString::number(brox,'f',2).toDouble());
                    xlsx.write(i+8,11,QString::number(r2rox,'f',2).toDouble());
                    xlsx.write(i+8,12,QString::number(krox,'f',2).toDouble());
                    xlsx.write(i+8,13,QString::number(curox,'f',2)+"%");
                    xlsx.write(i+9,10,QString::number(bvic,'f',2).toDouble());
                    xlsx.write(i+9,11,QString::number(r2vic,'f',2).toDouble());
                    xlsx.write(i+9,12,QString::number(kvic,'f',2).toDouble());
                    xlsx.write(i+9,13,QString::number(cuvic,'f',2)+"%");
                }
            }else{
                for(int i=7;i<ui->tableWidget->rowCount()+7;i++){
                    for (int j=10;j<14;j++) {
                        xlsx.write(i,j," ");
                    }
                }
            }
            for(int i=0;i<ui->tableWidget->rowCount();i++){
                kong=ui->tableWidget->item(i,0)->text();
                kong=ui->tableWidget->item(i,1)->text();
                sample=ui->tableWidget->item(i,2)->text();
                tetype=ui->tableWidget->item(i,3)->text();
                lu=ui->tableWidget->item(i,4)->text();
                cq=ui->tableWidget->item(i,5)->text();
                qya=ui->tableWidget->item(i,6)->text();
                out<<kong<<"\t";
                out<<sample<<"\t";
                out<<tetype<<"\t";
                out<<lu<<"\t";
                out<<cq<<"\t";
                out<<qya<<"\t";
                if(MainWindow::isBzsy){
                    out<<qut[i]<<"\t";
                }else{
                    out<<" "<<"\t";
                }
                out2<<kong<<"\t";
                out2<<sample<<"\t";
                out2<<tetype<<"\t";
                out2<<lu<<"\t";
                out2<<cq<<"\t";
                out2<<qya<<"\t";
                if(MainWindow::isBzsy){
                    out2<<qut[i]<<"\t";
                }else{
                    out2<<" "<<"\t";
                }
                if((i+1)%4==1){
                    out<<QString::number(bfam)<<"\t"<<QString::number(r2fam)<<"\t"<<QString::number(kfam)<<"\t"<<QString::number(cufam)<<"\n";
                    out2<<QString::number(bfam)<<"\t"<<QString::number(r2fam)<<"\t"<<QString::number(kfam)<<"\t"<<QString::number(cufam)<<"\n";
                }else if((i+1)%4==2){
                    out<<QString::number(brox)<<"\t"<<QString::number(r2rox)<<"\t"<<QString::number(krox)<<"\t"<<QString::number(curox)<<"\n";
                    out2<<QString::number(brox)<<"\t"<<QString::number(r2rox)<<"\t"<<QString::number(krox)<<"\t"<<QString::number(curox)<<"\n";
                }else if((i+1)%4==3){
                    out<<QString::number(bvic)<<"\t"<<QString::number(r2vic)<<"\t"<<QString::number(kvic)<<"\t"<<QString::number(cuvic)<<"\n";
                    out2<<QString::number(bvic)<<"\t"<<QString::number(r2vic)<<"\t"<<QString::number(kvic)<<"\t"<<QString::number(cuvic)<<"\n";
                }else if((i+1)%4==0){
                    out<<QString::number(bcy5)<<"\t"<<QString::number(r2cy5)<<"\t"<<QString::number(kcy5)<<"\t"<<QString::number(cucy5)<<"\n";
                    out2<<QString::number(bcy5)<<"\t"<<QString::number(r2cy5)<<"\t"<<QString::number(kcy5)<<"\t"<<QString::number(cucy5)<<"\n";
                }
            }
        }
        if(true){
            xlsx.selectSheet("下游加样表格");
            for(int i=0;i<15;i++){
                xlsx.setColumnWidth(i+1,18);
            }
            for(int i=0;i<32;i++){
                xlsx.setRowHeight(i+1,22);
            }
            // 创建一个Format对象
            QXlsx::Format format2;
            format2.setBorderStyle(QXlsx::Format::BorderMedium);
            format2.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            QXlsx::Format format;
            format.setPatternBackgroundColor(QColor(152, 245, 255));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(1,1,"常-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(1,i+2,"",format);
            }
            format.setPatternBackgroundColor(QColor(0, 255, 0));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(12,1,"Y-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(12,i+2,"",format);
            }
            format.setPatternBackgroundColor(QColor(255, 255, 0));
            format.setBorderStyle(QXlsx::Format::BorderMedium);
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);;
            xlsx.write(23,1,"mini-STR加样表格",format);
            for(int i=0;i<4;i++){
                xlsx.write(23,i+2,"",format);
            }
            int zmfl=3;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            zmfl=14;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            zmfl=25;
            for(char zm='A';zm<='F';zm++){
                QString kdata =QString(zm);
                xlsx.write(zmfl,1,kdata,format2);
                zmfl++;
            }
            for(int i=1;i<5;i++){
                xlsx.write(2,i+1,QString::number(i),format2);
                xlsx.write(13,i+1,QString::number(i),format2);
                xlsx.write(24,i+1,QString::number(i),format2);
            }
            QString L="";
            QString N="";
            QString LN="";
            QStringList hang,lie;
            for(int i=2;i<6;i++){
                hang.append(QString::number(i-1));
            }
            for(char kong1='A';kong1<='F';kong1++){
                lie.append(QString(kong1));
            }

            for(int i=3;i<9;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-3];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="常STR"||ui->tableWidget->item(k,13)->text()=="常STR+Y-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }
            }
            for(int i=9;i<12;i++){
                for(int j=1;j<6;j++){
                    xlsx.write(i,j,"",format2);
                }
            }
            for(int i=14;i<20;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-14];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="常STR+Y-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }
            }
            for(int i=20;i<23;i++){
                for(int j=1;j<6;j++){
                    xlsx.write(i,j,"",format2);
                }
            }
            for(int i=25;i<31;i++){
                for(int j=2;j<6;j++){
                    L = lie[i-25];
                    N = hang[j-2];
                    LN = L + N;
                    xlsx.write(i,j,"",format2);
                    for(int k = 0;k<ui->tableWidget->rowCount();k+=4){
                        if(ui->tableWidget->item(k,13)->text()=="二代测序或mini-STR"){
                            if(LN==ui->tableWidget->item(k,1)->text()){
                                QString sytj = ui->tableWidget->item(k,16)->text();
                                xlsx.write(i,j,sytj,format2);
                            }
                        }
                    }
                }

            }
        }
        if(isc=="1"){
            QString directory = "./dataout";
            if(doutfl==1){
                directory=outpath;
            }
            QDir dir;
            if (!dir.exists(directory)) {
                dir.mkpath(directory); // 创建目录
            }
            QString fullPath = directory + "/" + fileName;
            QString fullPath2 = directory + "/" + fileName2;

            if (xlsx.saveAs(fullPath)) {

            } else {

            }
            if (xlsx.saveAs(fullPath2)) {
            } else {
            }
            // 关闭文件
            file.close();
            file2.close();
            if(doutfl!=1){
                QString directory1 = filep;
                if(filep!=""){
                    QDir dir1;
                    if (!dir1.exists(directory1)) {
                        dir1.mkpath(directory1); // 创建目录
                    }
                    QString fullPath = directory1 + "/" + fileName;
                    QString fullPath2 = directory1 + "/" + fileName2;

                    if (xlsx.saveAs(fullPath)) {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","treat","导出成功！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    } else {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","error","导出失败！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    }
                    if (xlsx.saveAs(fullPath2)) {
                    } else {
                    }
                }
            }
            if(doutfl==1){
                QString directory1 = outpath;
                if(filep!=""){
                    QDir dir1;
                    if (!dir1.exists(directory1)) {
                        dir1.mkpath(directory1); // 创建目录
                    }
                    QString fullPath = directory1 + "/" + fileName;
                    QString fullPath2 = directory1 + "/" + fileName2;
                    QString fullPath4 = directory1 + "/" + "_test.txt";
                    if (xlsx.saveAs(fullPath)) {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","treat","导出成功！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    } else {
                        tcts1 = new tcts();
                        tcts1->infochange("提示","error","导出！",false,true);
                        tcts1->setAttribute(Qt::WA_DeleteOnClose); //关掉消息框后删除指针
                        tcts1->show();
                    }
                    if (xlsx.saveAs(fullPath2)) {
                    } else {
                    }
                }
            }
        }
    }
    ui->FAMCheckBox->setChecked(famcb);
    ui->VICCheckBox->setChecked(viccb);
    ui->ROXCheckBox->setChecked(roxcb);
    ui->CY5CheckBox->setChecked(cy5cb);
}

void DataAnalysisWindow::on_pushButton_9_clicked()
{
    this->hide();
    refWindow=false;
    emit changeSampleWindow();
}

void DataAnalysisWindow::on_pushButton_10_clicked()
{
    this->hide();
    refWindow=false;
    emit changeExperiInfoWindow();
}

void DataAnalysisWindow::on_pushButton_clicked()
{
    if(vsfl1==0){
        ui->widget_2->setVisible(false);
        ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        ui->pushButton_6->setVisible(false);
        vsfl1=1;
    }else if (vsfl1==1) {
        ui->widget_2->setVisible(true);
        ui->pushButton->setStyleSheet("border-image: url(:/pic/picture/left.png);");
        ui->pushButton_6->setVisible(true);
        vsfl1=0;
    }

}

void DataAnalysisWindow::on_pushButton_6_clicked()
{
    if(vsfl2==0){
        ui->widget_3->setVisible(false);
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/left.png);");
        ui->pushButton->setVisible(false);
        vsfl2=1;
    }else if (vsfl2==1) {
        ui->widget_3->setVisible(true);
        ui->pushButton_6->setStyleSheet("border-image: url(:/pic/picture/right.png);");
        ui->pushButton->setVisible(true);
        vsfl2=0;
    }
}

void DataAnalysisWindow::on_pushButton_2_clicked()
{
    QString filePath = QFileDialog::getSaveFileName(this, "保存", "/path/to/default/directory");
    if(filePath.isEmpty()&&filePath.isNull()){
        return;
    }
    QPixmap p = ui->graphicsView->grab();
    QImage image = p.toImage();
    image.save(filePath+".png");
}
// 导出按钮
void DataAnalysisWindow::on_pushButton_3_clicked()
{
    QString tabfl = ui->comboBox->currentText();
    doutfl=1;
    // 获取用户选择的文件夹路径
//    outpath = QFileDialog::getExistingDirectory(this,
//                                                tr("选择文件夹"),
//                                                QDir::currentPath(), // 初始目录
//                                                QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    // 设置文件过滤器，以便用户只能选择xlsx文件
    QString fileFilter = tr("Excel files (*.xlsx)");
    QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss");
    fileName = currentTime + "_test.xlsx";

    // 使用getSaveFileName来获取用户选择的文件名和路径
    QString filePath = QFileDialog::getSaveFileName(this,
                                                    tr("保存Excel文件"),
                                                    QDir::currentPath() + "/" + fileName, // 初始目录
                                                    fileFilter);
    if (!filePath.isEmpty()) {
        // 使用QFileInfo来分别获取路径和文件名
        QFileInfo fileInfo(filePath);
        outpath = fileInfo.absolutePath(); // 获取路径
        fileName = fileInfo.fileName(); // 获取文件名（包括扩展名）
        fileName2 = fileInfo.baseName()+".csv";
        fileName3 = fileInfo.baseName()+".txt";

        // 执行文件导出操作...
    }
//    if(outpath==""){
//        return;
//    }
    refOriginalCurveTable();
    refAmplificationCurveTable();
    standardCurveChart();
    guide();
    datao();
    doutfl=0;
    ui->comboBox->currentTextChanged(tabfl);
}

void DataAnalysisWindow::on_pushButton_7_clicked()
{
    on_clicked_leftmouse1(1);
}

void DataAnalysisWindow::on_pushButton_8_clicked()
{
    on_clicked_leftmouse1(4);
}

void DataAnalysisWindow::on_pushButton_11_clicked()
{
    on_clicked_leftmouse1(5);
}

void DataAnalysisWindow::on_pushButton_12_clicked()
{
    on_clicked_leftmouse1(3);
}

void DataAnalysisWindow::on_pushButton_13_clicked()
{
    on_clicked_leftmouse1(2);
}

void DataAnalysisWindow::on_pushButton_14_clicked()
{
    on_clicked_leftmouse1(6);
}

// 求平均 7.16 cnr
double DataAnalysisWindow::Mean(QList<double> CQval){
    double sum=0;
    for(int i=0;i<CQval.length();i++){
        if (std::isnan(CQval[i])) {
            sum+=0.00; // 如果是NaN，则设置为0
        }else{
            sum+=CQval[i];
        }
    }
    return sum/CQval.length();
}

// 求标准差 7.16 cnr
double DataAnalysisWindow::STD(QList<double> CQval){
    double mean = Mean(CQval);
    double accum = 0.0;
    for(int i=0;i<CQval.length();i++){
        if (std::isnan(CQval[i])) {
            accum+=(0.0-mean) * (0.0-mean);
        }else{
            accum+=(CQval[i]-mean) * (CQval[i]-mean);
        }
    }
    return sqrt(accum / CQval.length());
}

void DataAnalysisWindow::on_pushButton_15_clicked()
{
    anscrui->show();
    connect(anscrui->ui->pushButton_3,SIGNAL(clicked()),this,SLOT(refl()));// 曲线表格刷新
}

void DataAnalysisWindow::on_pushButton_16_clicked()
{
    fxpzui->show();
    if(isYing){
        connect(fxpzui->ui->pushButton_3,SIGNAL(clicked()),this,SLOT(refl()));// 曲线表格刷新
    }
}

// 刷新曲线表格
void DataAnalysisWindow::refl(){
    QString arg1= ui->comboBox->currentText();
    if(arg1=="原始曲线"){
        refOriginalCurveChart();
        refOriginalCurveTable();
    }else if(arg1 =="扩增曲线"){
        refAmplificationCurveChart();
        refAmplificationCurveTable();
    }else if(arg1=="标准曲线"){
        refOriginalCurveTable();
        refAmplificationCurveTable();
        standardCurveChart();
    }else if(arg1=="指导建议"){
        refOriginalCurveTable();
        refAmplificationCurveTable();
        standardCurveChart();
        guide();
    }
}
